447 lines
16 KiB
TypeScript
447 lines
16 KiB
TypeScript
import {
|
|
bigint,
|
|
boolean,
|
|
doublePrecision,
|
|
foreignKey,
|
|
integer,
|
|
pgTable,
|
|
text,
|
|
varchar,
|
|
} from "drizzle-orm/pg-core";
|
|
import { sql as _sql } from "drizzle-orm";
|
|
|
|
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" }),
|
|
// 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" }),
|
|
encryptedData: text("encrypted_data"),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.userId],
|
|
foreignColumns: [users.id],
|
|
name: "incomes_user_id_users_id_fk",
|
|
}),
|
|
]);
|
|
|
|
export const leases = pgTable("leases", {
|
|
id: text().primaryKey().notNull(),
|
|
title: text(),
|
|
propertyId: text("property_id"),
|
|
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"),
|
|
// 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" }),
|
|
encryptedData: text("encrypted_data"),
|
|
propertyAddress: text("property_address"),
|
|
leaseDocumentUrl: text("lease_document_url"),
|
|
paymentScheduleId: text("payment_schedule_id"),
|
|
lateFeeRules: text("late_fee_rules"),
|
|
autoRenewal: boolean("auto_renewal").default(false),
|
|
}, (table) => [
|
|
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.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",
|
|
}),
|
|
]);
|
|
|
|
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 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"),
|
|
imageUrl: text("image_url"),
|
|
// 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"),
|
|
encryptedData: text("encrypted_data"),
|
|
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),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.ownerId],
|
|
foreignColumns: [users.id],
|
|
name: "properties_owner_id_users_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(),
|
|
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" }),
|
|
content: text(),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.leaseId],
|
|
foreignColumns: [leases.id],
|
|
name: "messages_lease_id_leases_id_fk",
|
|
}),
|
|
foreignKey({
|
|
columns: [table.recipientId],
|
|
foreignColumns: [users.id],
|
|
name: "messages_recipient_id_users_id_fk",
|
|
}),
|
|
foreignKey({
|
|
columns: [table.senderId],
|
|
foreignColumns: [users.id],
|
|
name: "messages_sender_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" }),
|
|
// 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" }),
|
|
encryptedData: text("encrypted_data"),
|
|
}, (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 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 roles = pgTable("roles", {
|
|
id: text().primaryKey().notNull(),
|
|
description: text(),
|
|
});
|
|
|
|
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" }),
|
|
// 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" }),
|
|
encryptedData: text("encrypted_data"),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.userId],
|
|
foreignColumns: [users.id],
|
|
name: "financial_balances_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.roleId],
|
|
foreignColumns: [roles.id],
|
|
name: "user_roles_role_id_roles_id_fk",
|
|
}),
|
|
foreignKey({
|
|
columns: [table.userId],
|
|
foreignColumns: [users.id],
|
|
name: "user_roles_user_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(),
|
|
// 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" }),
|
|
encryptedData: text("encrypted_data"),
|
|
userType: text("user_type"),
|
|
onboardedLandlord: boolean("onboarded_landlord").default(false),
|
|
onboardedTenant: boolean("onboarded_tenant").default(false),
|
|
emailVerified: boolean("email_verified").default(false),
|
|
bankingSetupComplete: boolean("banking_setup_complete").default(false),
|
|
onboardingStep: integer("onboarding_step").default(0),
|
|
});
|
|
|
|
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 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" }),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.applicantId],
|
|
foreignColumns: [users.id],
|
|
name: "tenant_applications_applicant_id_users_id_fk",
|
|
}),
|
|
foreignKey({
|
|
columns: [table.propertyId],
|
|
foreignColumns: [properties.id],
|
|
name: "tenant_applications_property_id_properties_id_fk",
|
|
}),
|
|
]);
|
|
|
|
export const tenantInvites = pgTable("tenant_invites", {
|
|
id: text().primaryKey().notNull(),
|
|
landlordId: text("landlord_id"),
|
|
propertyId: text("property_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",
|
|
}),
|
|
]);
|
|
|
|
export const userTokens = pgTable("user_tokens", {
|
|
userId: text("user_id").primaryKey().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) => [
|
|
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",
|
|
}),
|
|
]);
|