Introduced New DB
This commit is contained in:
140
db/schema/tenants.ts
Normal file
140
db/schema/tenants.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
import {
|
||||
pgTable,
|
||||
bigint,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
jsonb,
|
||||
integer,
|
||||
smallint,
|
||||
date,
|
||||
uuid,
|
||||
pgEnum,
|
||||
} from "drizzle-orm/pg-core"
|
||||
import { authUsers } from "./auth_users"
|
||||
import {lockedTenantEnum} from "./enums";
|
||||
|
||||
export const tenants = pgTable(
|
||||
"tenants",
|
||||
{
|
||||
id: bigint("id", { mode: "number" })
|
||||
.primaryKey()
|
||||
.generatedByDefaultAsIdentity(),
|
||||
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow(),
|
||||
|
||||
name: text("name").notNull(),
|
||||
short: text("short").notNull(),
|
||||
|
||||
calendarConfig: jsonb("calendarConfig").default({
|
||||
eventTypes: [
|
||||
{ color: "blue", label: "Büro" },
|
||||
{ color: "yellow", label: "Besprechung" },
|
||||
{ color: "green", label: "Umsetzung" },
|
||||
{ color: "red", label: "Vor Ort Termin" },
|
||||
],
|
||||
}),
|
||||
|
||||
timeConfig: jsonb("timeConfig").notNull().default({}),
|
||||
|
||||
tags: jsonb("tags").notNull().default({
|
||||
products: [],
|
||||
documents: [],
|
||||
}),
|
||||
|
||||
measures: jsonb("measures")
|
||||
.notNull()
|
||||
.default([
|
||||
{ name: "Netzwerktechnik", short: "NWT" },
|
||||
{ name: "Elektrotechnik", short: "ELT" },
|
||||
{ name: "Photovoltaik", short: "PV" },
|
||||
{ name: "Videüberwachung", short: "VÜA" },
|
||||
{ name: "Projekt", short: "PRJ" },
|
||||
{ name: "Smart Home", short: "SHO" },
|
||||
]),
|
||||
|
||||
businessInfo: jsonb("businessInfo").default({
|
||||
zip: "",
|
||||
city: "",
|
||||
name: "",
|
||||
street: "",
|
||||
}),
|
||||
|
||||
features: jsonb("features").default({
|
||||
objects: true,
|
||||
calendar: true,
|
||||
contacts: true,
|
||||
projects: true,
|
||||
vehicles: true,
|
||||
contracts: true,
|
||||
inventory: true,
|
||||
accounting: true,
|
||||
timeTracking: true,
|
||||
planningBoard: true,
|
||||
workingTimeTracking: true,
|
||||
}),
|
||||
|
||||
ownFields: jsonb("ownFields"),
|
||||
|
||||
numberRanges: jsonb("numberRanges")
|
||||
.notNull()
|
||||
.default({
|
||||
vendors: { prefix: "", suffix: "", nextNumber: 10000 },
|
||||
customers: { prefix: "", suffix: "", nextNumber: 10000 },
|
||||
products: { prefix: "AT-", suffix: "", nextNumber: 1000 },
|
||||
quotes: { prefix: "AN-", suffix: "", nextNumber: 1000 },
|
||||
confirmationOrders: { prefix: "AB-", suffix: "", nextNumber: 1000 },
|
||||
invoices: { prefix: "RE-", suffix: "", nextNumber: 1000 },
|
||||
spaces: { prefix: "LP-", suffix: "", nextNumber: 1000 },
|
||||
inventoryitems: { prefix: "IA-", suffix: "", nextNumber: 1000 },
|
||||
projects: { prefix: "PRJ-", suffix: "", nextNumber: 1000 },
|
||||
costcentres: { prefix: "KST-", suffix: "", nextNumber: 1000 },
|
||||
}),
|
||||
|
||||
standardEmailForInvoices: text("standardEmailForInvoices"),
|
||||
|
||||
extraModules: jsonb("extraModules").notNull().default([]),
|
||||
|
||||
isInTrial: boolean("isInTrial").default(false),
|
||||
trialEndDate: date("trialEndDate"),
|
||||
|
||||
stripeCustomerId: text("stripeCustomerId"),
|
||||
|
||||
hasActiveLicense: boolean("hasActiveLicense").notNull().default(false),
|
||||
|
||||
userLicenseCount: integer("userLicenseCount")
|
||||
.notNull()
|
||||
.default(0),
|
||||
|
||||
workstationLicenseCount: integer("workstationLicenseCount")
|
||||
.notNull()
|
||||
.default(0),
|
||||
|
||||
standardPaymentDays: smallint("standardPaymentDays")
|
||||
.notNull()
|
||||
.default(14),
|
||||
|
||||
dokuboxEmailAddresses: jsonb("dokuboxEmailAddresses").default([]),
|
||||
|
||||
dokuboxkey: uuid("dokuboxkey").notNull().defaultRandom(),
|
||||
|
||||
autoPrepareIncomingInvoices: boolean("autoPrepareIncomingInvoices")
|
||||
.default(true),
|
||||
|
||||
portalDomain: text("portalDomain"),
|
||||
|
||||
portalConfig: jsonb("portalConfig")
|
||||
.notNull()
|
||||
.default({ primayColor: "#69c350" }),
|
||||
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }),
|
||||
updatedBy: uuid("updated_by").references(() => authUsers.id),
|
||||
|
||||
locked: lockedTenantEnum("locked"),
|
||||
}
|
||||
)
|
||||
|
||||
export type Tenant = typeof tenants.$inferSelect
|
||||
export type NewTenant = typeof tenants.$inferInsert
|
||||
Reference in New Issue
Block a user