2026-02-14 02:20:19 +00:00

543 lines
20 KiB
TypeScript

import {
bigint,
boolean,
doublePrecision,
foreignKey,
integer,
json,
pgTable,
primaryKey,
text,
varchar,
} from "drizzle-orm/pg-core";
export const stateKeys = pgTable("state_keys", {
sealKey: varchar("seal_key", { length: 32 }).primaryKey().notNull(),
stateId: varchar("state_id", { length: 36 }).notNull(),
cookieHash: varchar("cookie_hash", { length: 64 }).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }).notNull(),
});
export const financialBalances = pgTable("financial_balances", {
id: text().primaryKey().notNull(),
userId: text("user_id"),
balance: doublePrecision(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
balanceDate: bigint("balance_date", { mode: "number" }),
encryptedData: text("encrypted_data"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "financial_balances_user_id_users_id_fk",
}),
]);
export const incomes = pgTable("incomes", {
id: text().primaryKey().notNull(),
userId: text("user_id"),
source: text(),
amount: doublePrecision(),
frequency: text(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
receivedDate: bigint("received_date", { mode: "number" }),
encryptedData: text("encrypted_data"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "incomes_user_id_users_id_fk",
}),
]);
export const leaseDocuments = pgTable("lease_documents", {
id: text().primaryKey().notNull(),
leaseId: text("lease_id"),
documentType: text("document_type"),
fileUrl: text("file_url"),
fileName: text("file_name"),
signedByLandlord: boolean("signed_by_landlord").default(false),
signedByTenant: boolean("signed_by_tenant").default(false),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
signatureDate: bigint("signature_date", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.leaseId],
foreignColumns: [leases.id],
name: "lease_documents_lease_id_leases_id_fk",
}),
]);
export const rentSchedules = pgTable("rent_schedules", {
id: text().primaryKey().notNull(),
propertyId: text("property_id"),
rentAmount: doublePrecision("rent_amount"),
dueDay: integer("due_day"),
lateFeeAmount: doublePrecision("late_fee_amount"),
gracePeriodDays: integer("grace_period_days").default(0),
paymentMethodsAllowed: text("payment_methods_allowed"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.propertyId],
foreignColumns: [properties.id],
name: "rent_schedules_property_id_properties_id_fk",
}),
]);
export const maintenanceRequests = pgTable("maintenance_requests", {
id: text().primaryKey().notNull(),
propertyId: text("property_id"),
tenantId: text("tenant_id"),
requestType: text("request_type"),
description: text(),
status: text(),
priority: text(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
resolvedOn: bigint("resolved_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.propertyId],
foreignColumns: [properties.id],
name: "maintenance_requests_property_id_properties_id_fk",
}),
foreignKey({
columns: [table.tenantId],
foreignColumns: [users.id],
name: "maintenance_requests_tenant_id_users_id_fk",
}),
]);
export const obligations = pgTable("obligations", {
id: text().primaryKey().notNull(),
userId: text("user_id"),
description: text(),
amount: doublePrecision(),
frequency: text(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
dueDate: bigint("due_date", { mode: "number" }),
encryptedData: text("encrypted_data"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "obligations_user_id_users_id_fk",
}),
]);
export const paymentMethods = pgTable("payment_methods", {
id: text().primaryKey().notNull(),
userId: text("user_id"),
methodType: text("method_type"),
bankName: text("bank_name"),
accountType: text("account_type"),
routingNumberEncrypted: text("routing_number_encrypted"),
accountNumberEncrypted: text("account_number_encrypted"),
isDefault: boolean("is_default").default(false),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "payment_methods_user_id_users_id_fk",
}),
]);
export const paymentTransactions = pgTable("payment_transactions", {
id: text().primaryKey().notNull(),
leaseId: text("lease_id"),
amount: doublePrecision(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
paymentDate: bigint("payment_date", { mode: "number" }),
paymentMethod: text("payment_method"),
transactionStatus: text("transaction_status"),
stripePaymentId: text("stripe_payment_id"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.leaseId],
foreignColumns: [leases.id],
name: "payment_transactions_lease_id_leases_id_fk",
}),
]);
export const propertyMedia = pgTable("property_media", {
id: text().primaryKey().notNull(),
propertyId: text("property_id"),
mediaType: text("media_type"),
fileUrl: text("file_url"),
fileName: text("file_name"),
displayOrder: integer("display_order").default(0),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.propertyId],
foreignColumns: [properties.id],
name: "property_media_property_id_properties_id_fk",
}),
]);
export const sessionConfigs = pgTable("session_configs", {
deviceId: text("device_id").primaryKey().notNull(),
userId: text("user_id"),
otherData: text("other_data"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
activeDate: bigint("active_date", { mode: "number" }),
activeRoute: text("active_route"),
pageData: text("page_data"),
}, (table) => [
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "session_configs_user_id_users_id_fk",
}),
]);
export const userRoles = pgTable("user_roles", {
id: text().primaryKey().notNull(),
userId: text("user_id"),
roleId: text("role_id"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "user_roles_user_id_users_id_fk",
}),
foreignKey({
columns: [table.roleId],
foreignColumns: [roles.id],
name: "user_roles_role_id_roles_id_fk",
}),
]);
export const roles = pgTable("roles", {
id: text().primaryKey().notNull(),
description: text(),
});
export const userTokens = pgTable("user_tokens", {
userId: text("user_id").notNull(),
stateId: text("state_id").notNull(),
accessToken: text("access_token").notNull(),
refreshToken: text("refresh_token").notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
}, (table) => [
primaryKey({ columns: [table.userId, table.stateId] }),
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "user_tokens_user_id_users_id_fk",
}),
]);
export const userPins = pgTable("user_pins", {
userId: text("user_id").primaryKey().notNull(),
pin: text().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
modifiedOn: bigint("modified_on", { mode: "number" }).notNull(),
}, (table) => [
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "user_pins_user_id_users_id_fk",
}),
]);
export const leases = pgTable("leases", {
id: text().primaryKey().notNull(),
title: text(),
propertyId: text("property_id"),
propertyAddress: text("property_address"),
tenantId: text("tenant_id"),
ownerId: text("owner_id"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
startDate: bigint("start_date", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
endDate: bigint("end_date", { mode: "number" }),
rent: doublePrecision(),
securityDeposit: doublePrecision("security_deposit"),
leaseStatus: text("lease_status"),
leaseDocumentUrl: text("lease_document_url"),
paymentScheduleId: text("payment_schedule_id"),
lateFeeRules: text("late_fee_rules"),
autoRenewal: boolean("auto_renewal").default(false),
encryptedData: text("encrypted_data"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
defaultPaymentMethodId: text("default_payment_method_id"),
}, (table) => [
foreignKey({
columns: [table.propertyId],
foreignColumns: [properties.id],
name: "leases_property_id_properties_id_fk",
}),
foreignKey({
columns: [table.tenantId],
foreignColumns: [users.id],
name: "leases_tenant_id_users_id_fk",
}),
foreignKey({
columns: [table.ownerId],
foreignColumns: [users.id],
name: "leases_owner_id_users_id_fk",
}),
foreignKey({
columns: [table.paymentScheduleId],
foreignColumns: [rentSchedules.id],
name: "leases_payment_schedule_id_rent_schedules_id_fk",
}),
foreignKey({
columns: [table.defaultPaymentMethodId],
foreignColumns: [paymentMethods.id],
name: "leases_default_payment_method_id_payment_methods_id_fk",
}),
]);
export const messages = pgTable("messages", {
id: text().primaryKey().notNull(),
leaseId: text("lease_id"),
senderId: text("sender_id"),
recipientId: text("recipient_id"),
messageType: text("message_type"),
subject: text(),
content: text(),
contentEncrypted: text("content_encrypted"),
isRead: boolean("is_read").default(false),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
parentMessageId: text("parent_message_id"),
attachmentsJson: json("attachments_json"),
}, (table) => [
foreignKey({
columns: [table.leaseId],
foreignColumns: [leases.id],
name: "messages_lease_id_leases_id_fk",
}),
foreignKey({
columns: [table.senderId],
foreignColumns: [users.id],
name: "messages_sender_id_users_id_fk",
}),
foreignKey({
columns: [table.recipientId],
foreignColumns: [users.id],
name: "messages_recipient_id_users_id_fk",
}),
]);
export const properties = pgTable("properties", {
id: text().primaryKey().notNull(),
title: text(),
description: text(),
address1: text("address_1"),
address2: text("address_2"),
city: text(),
state: text(),
zip: text(),
country: text(),
bedrooms: integer(),
bathrooms: integer(),
squareFootage: integer("square_footage"),
lotSize: integer("lot_size"),
yearBuilt: integer("year_built"),
price: doublePrecision(),
propertyType: text("property_type"),
listingStatus: text("listing_status"),
rentalStatus: text("rental_status"),
monthlyRent: doublePrecision("monthly_rent"),
securityDeposit: doublePrecision("security_deposit"),
leaseDurationMonths: integer("lease_duration_months"),
amenities: text(),
propertyPhotosCount: integer("property_photos_count").default(0),
imageUrl: text("image_url"),
encryptedData: text("encrypted_data"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
ownerId: text("owner_id"),
defaultPaymentMethodId: text("default_payment_method_id"),
}, (table) => [
foreignKey({
columns: [table.ownerId],
foreignColumns: [users.id],
name: "properties_owner_id_users_id_fk",
}),
foreignKey({
columns: [table.defaultPaymentMethodId],
foreignColumns: [paymentMethods.id],
name: "properties_default_payment_method_id_payment_methods_id_fk",
}),
]);
export const tenantApplications = pgTable("tenant_applications", {
id: text().primaryKey().notNull(),
propertyId: text("property_id"),
applicantId: text("applicant_id"),
applicationStatus: text("application_status"),
applicationDataEncrypted: text("application_data_encrypted"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
submittedOn: bigint("submitted_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
reviewedOn: bigint("reviewed_on", { mode: "number" }),
documentUrlsJson: json("document_urls_json"),
}, (table) => [
foreignKey({
columns: [table.propertyId],
foreignColumns: [properties.id],
name: "tenant_applications_property_id_properties_id_fk",
}),
foreignKey({
columns: [table.applicantId],
foreignColumns: [users.id],
name: "tenant_applications_applicant_id_users_id_fk",
}),
]);
export const users = pgTable("users", {
id: text().primaryKey().notNull(),
name: text(),
email: text(),
phone: text(),
address1: text("address_1"),
address2: text("address_2"),
city: text(),
state: text(),
zip: text(),
country: text(),
userType: text("user_type"),
emailVerified: boolean("email_verified").default(false),
bankingSetupComplete: boolean("banking_setup_complete").default(false),
onboardingStep: integer("onboarding_step").default(0),
encryptedData: text("encrypted_data"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
startedOn: bigint("started_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
onboardedLandlord: boolean("onboarded_landlord").default(false),
onboardedTenant: boolean("onboarded_tenant").default(false),
notificationPreferencesJson: json("notification_preferences_json"),
paymentPreferencesJson: json("payment_preferences_json"),
});
export const reminders = pgTable("reminders", {
id: text().primaryKey().notNull(),
userId: text("user_id").notNull(),
leaseId: text("lease_id"),
reminderType: text("reminder_type").notNull(),
title: text().notNull(),
description: text(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
dueDate: bigint("due_date", { mode: "number" }).notNull(),
isCompleted: boolean("is_completed").default(false),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "reminders_user_id_users_id_fk",
}),
foreignKey({
columns: [table.leaseId],
foreignColumns: [leases.id],
name: "reminders_lease_id_leases_id_fk",
}),
]);
export const tenantInvites = pgTable("tenant_invites", {
id: text().primaryKey().notNull(),
landlordId: text("landlord_id"),
propertyId: text("property_id"),
leaseId: text("lease_id"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
availableOn: bigint("available_on", { mode: "number" }),
invitedEmails: text("invited_emails"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }),
}, (table) => [
foreignKey({
columns: [table.landlordId],
foreignColumns: [users.id],
name: "tenant_invites_landlord_id_users_id_fk",
}),
foreignKey({
columns: [table.propertyId],
foreignColumns: [properties.id],
name: "tenant_invites_property_id_properties_id_fk",
}),
foreignKey({
columns: [table.leaseId],
foreignColumns: [leases.id],
name: "tenant_invites_lease_id_leases_id_fk",
}),
]);
export const webTokens = pgTable("web_tokens", {
tokenId: varchar("token_id", { length: 64 }).primaryKey().notNull(),
stateId: varchar("state_id", { length: 36 }).notNull(),
userId: text("user_id").notNull(),
tokenType: text("token_type").notNull(),
tokenValue: text("token_value").notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
expiresOn: bigint("expires_on", { mode: "number" }).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
createdOn: bigint("created_on", { mode: "number" }).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
updatedOn: bigint("updated_on", { mode: "number" }).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
lastUsedOn: bigint("last_used_on", { mode: "number" }),
isActive: boolean("is_active").default(true),
metadata: json(),
}, (table) => [
foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "web_tokens_user_id_users_id_fk",
}),
]);
export const alembicVersion = pgTable("alembic_version", {
versionNum: varchar("version_num", { length: 32 }).primaryKey().notNull(),
});