From 3f8dd9bcd9029f2480648d2303d47928036ad301 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Fri, 20 Mar 2026 13:56:18 +0000 Subject: [PATCH] added new tables --- src/app/db/schema/organisation.ts | 17 +++++++++ src/app/db/schema/team.ts | 59 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/app/db/schema/organisation.ts create mode 100644 src/app/db/schema/team.ts diff --git a/src/app/db/schema/organisation.ts b/src/app/db/schema/organisation.ts new file mode 100644 index 0000000..2358104 --- /dev/null +++ b/src/app/db/schema/organisation.ts @@ -0,0 +1,17 @@ +import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"; +import { InferModel } from "drizzle-orm"; + +export const organisation = pgTable("organisation", { + id: uuid("id").defaultRandom().primaryKey(), + createdAt: timestamp("created_at", { precision: 6, withTimezone: true }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { precision: 6, withTimezone: true }) + .defaultNow() + .notNull(), + hubspotCompanyId: text("hubspot_company_id"), + companyName: text("company_name"), +}); + +export type Organisation = InferModel; +export type NewOrganisation = InferModel; diff --git a/src/app/db/schema/team.ts b/src/app/db/schema/team.ts new file mode 100644 index 0000000..e89e1e2 --- /dev/null +++ b/src/app/db/schema/team.ts @@ -0,0 +1,59 @@ +import { pgTable, text, timestamp, uuid, bigint } from "drizzle-orm/pg-core"; +import { InferModel } from "drizzle-orm"; +import { organisation } from "./organisation"; +import { user } from "./users"; +import { portfolio, roleEnum } from "./portfolio"; + +export const team = pgTable("team", { + id: uuid("id").defaultRandom().primaryKey(), + teamName: text("team_name").notNull(), + orgId: uuid("org_id").notNull().references(() => organisation.id), + createdAt: timestamp("created_at", { precision: 6, withTimezone: true }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { precision: 6, withTimezone: true }) + .defaultNow() + .notNull(), +}); + +export const teamMembers = pgTable("team_members", { + id: uuid("id").defaultRandom().primaryKey(), + userId: bigint("user_id", { mode: "bigint" }) + .notNull() + .references(() => user.id), + teamId: uuid("team_id").notNull().references(() => team.id), + createdAt: timestamp("created_at", { precision: 6, withTimezone: true }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { precision: 6, withTimezone: true }) + .defaultNow() + .notNull(), +}); + +export const teamPortfolioPermissions = pgTable("team_portfolio_permissions", { + id: uuid("id").defaultRandom().primaryKey(), + teamId: uuid("team_id").notNull().references(() => team.id), + portfolioId: bigint("portfolio_id", { mode: "bigint" }) + .notNull() + .references(() => portfolio.id), + role: roleEnum("role").notNull(), + createdAt: timestamp("created_at", { precision: 6, withTimezone: true }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { precision: 6, withTimezone: true }) + .defaultNow() + .notNull(), +}); + +export type Team = InferModel; +export type NewTeam = InferModel; +export type TeamMembers = InferModel; +export type NewTeamMembers = InferModel; +export type TeamPortfolioPermissions = InferModel< + typeof teamPortfolioPermissions, + "select" +>; +export type NewTeamPortfolioPermissions = InferModel< + typeof teamPortfolioPermissions, + "insert" +>;