Add to db schema
This commit is contained in:
parent
f070bb0175
commit
c21ae7452b
@ -3,8 +3,10 @@ import {
|
|||||||
timestamp,
|
timestamp,
|
||||||
pgTable,
|
pgTable,
|
||||||
text,
|
text,
|
||||||
|
pgEnum,
|
||||||
primaryKey,
|
primaryKey,
|
||||||
integer,
|
integer,
|
||||||
|
numeric,
|
||||||
} from "drizzle-orm/pg-core"
|
} from "drizzle-orm/pg-core"
|
||||||
import postgres from "postgres"
|
import postgres from "postgres"
|
||||||
import { drizzle } from "drizzle-orm/postgres-js"
|
import { drizzle } from "drizzle-orm/postgres-js"
|
||||||
@ -12,18 +14,29 @@ import type { AdapterAccountType } from "next-auth/adapters"
|
|||||||
|
|
||||||
const connectionString = process.env.DATABASE_URL ?? "";
|
const connectionString = process.env.DATABASE_URL ?? "";
|
||||||
const pool = postgres(connectionString, { max: 1 })
|
const pool = postgres(connectionString, { max: 1 })
|
||||||
|
|
||||||
export const db = drizzle(pool)
|
export const db = drizzle(pool)
|
||||||
|
|
||||||
export const users = pgTable("user", {
|
export const frequencyEnum = pgEnum("frequency", ["Monthly", "Bi-weekly", "Weekly"])
|
||||||
id: text("id")
|
export const workOrderStatusEnum = pgEnum("workOrderStatus", ["Pending", "Open", "Closed"])
|
||||||
.primaryKey()
|
export const preferredDaysofWeekEnum = pgEnum("preferredDaysofWeek",
|
||||||
.$defaultFn(() => crypto.randomUUID()),
|
["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"])
|
||||||
name: text("name"),
|
export const propertyTypeEnum = pgEnum("propertyType", ["Apartment", "Condominium",
|
||||||
email: text("email").unique(),
|
"Mobile Home", "Multi-Unit Home", "Single-Family Residence", "Townhouse"])
|
||||||
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
||||||
image: text("image"),
|
export const users = pgTable(
|
||||||
})
|
"user",
|
||||||
|
{
|
||||||
|
id: text("id")
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => crypto.randomUUID()),
|
||||||
|
name: text("name"),
|
||||||
|
email: text("email").unique().notNull(),
|
||||||
|
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
||||||
|
image: text("image"),
|
||||||
|
tenantID: text("tenantID").references(() => tenants.id, { onDelete: "cascade" }),
|
||||||
|
stripeCustomerID: text("stripeCustomerID"),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
export const accounts = pgTable(
|
export const accounts = pgTable(
|
||||||
"account",
|
"account",
|
||||||
@ -49,13 +62,16 @@ export const accounts = pgTable(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
export const sessions = pgTable("session", {
|
export const sessions = pgTable(
|
||||||
sessionToken: text("sessionToken").primaryKey(),
|
"session",
|
||||||
userId: text("userId")
|
{
|
||||||
.notNull()
|
sessionToken: text("sessionToken").primaryKey(),
|
||||||
.references(() => users.id, { onDelete: "cascade" }),
|
userId: text("userId")
|
||||||
expires: timestamp("expires", { mode: "date" }).notNull(),
|
.notNull()
|
||||||
})
|
.references(() => users.id, { onDelete: "cascade" }),
|
||||||
|
expires: timestamp("expires", { mode: "date" }).notNull(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
export const verificationTokens = pgTable(
|
export const verificationTokens = pgTable(
|
||||||
"verificationToken",
|
"verificationToken",
|
||||||
@ -91,3 +107,83 @@ export const authenticators = pgTable(
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const admins = pgTable(
|
||||||
|
"admin",
|
||||||
|
{
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
userID: text("userID").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const properties = pgTable(
|
||||||
|
"property",
|
||||||
|
{
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
address1: text("address1").unique().notNull(),
|
||||||
|
address2: text("address2"),
|
||||||
|
city: text("city").notNull(),
|
||||||
|
state: text("state").notNull(),
|
||||||
|
zip: text("zip").notNull(),
|
||||||
|
monthlyRent: numeric("monthlyRent").notNull(),
|
||||||
|
securityDeposit: numeric("securityDeposit"),
|
||||||
|
propertyType: propertyTypeEnum("propertyType").notNull(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const tenants = pgTable(
|
||||||
|
"tenant",
|
||||||
|
{
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
propertyID: text("propertyID").notNull().references(() => properties.id, { onDelete: "cascade" }),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const payments = pgTable(
|
||||||
|
"payment",
|
||||||
|
{
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
userID: text("userID").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||||
|
stripePaymentID: text("stripeID"),
|
||||||
|
amount: numeric("amount").notNull(),
|
||||||
|
paymentDate: timestamp("paymentDate").notNull(),
|
||||||
|
status: text("status").notNull(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const autoPayments = pgTable(
|
||||||
|
"autoPayment",
|
||||||
|
{
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
userID: text("userID").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||||
|
amount: numeric("amount").notNull(),
|
||||||
|
frequency: frequencyEnum("frequency").notNull(),
|
||||||
|
preferredDayofWeek: preferredDaysofWeekEnum("preferredDayofWeek").notNull(),
|
||||||
|
startDate: timestamp("startDate").notNull(),
|
||||||
|
nextPaymentDate: timestamp("nextPaymentDate").notNull(),
|
||||||
|
stripePaymentMethodID: text("stripePaymentMethodID").notNull(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const workorders = pgTable(
|
||||||
|
"workorder",
|
||||||
|
{
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
userID: text("userID").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||||
|
date: timestamp("date").notNull(),
|
||||||
|
status: workOrderStatusEnum("status").notNull().default("Pending"),
|
||||||
|
title: text("title").notNull(),
|
||||||
|
description: text("description"),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const documents = pgTable(
|
||||||
|
"document",
|
||||||
|
{
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
tenantID: text("tenantID").notNull().references(() => tenants.id, { onDelete: "cascade" }),
|
||||||
|
name: text("name").notNull(),
|
||||||
|
type: text("type").notNull(),
|
||||||
|
file: text("file").notNull(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user