Merge pull request #207 from Hestia-Homes/feature/new_way_of_doing_db
Some checks failed
Next.js Build Check / build (push) Has been cancelled

Feature/new way of doing db
This commit is contained in:
Jun-te Kim 2026-03-20 15:48:48 +00:00 committed by GitHub
commit 7e0eaa5044
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 6084 additions and 0 deletions

8
.claude/settings.json Normal file
View file

@ -0,0 +1,8 @@
{
"permissions": {
"deny": [
"Bash(npx drizzle-kit generate)",
"Bash(npx drizzle-kit push)"
]
}
}

View file

@ -0,0 +1,38 @@
CREATE TABLE "organisation" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"created_at" timestamp (6) with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp (6) with time zone DEFAULT now() NOT NULL,
"hubspot_company_id" text,
"company_name" text
);
--> statement-breakpoint
CREATE TABLE "team" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"team_name" text NOT NULL,
"org_id" uuid NOT NULL,
"created_at" timestamp (6) with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp (6) with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "team_members" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" bigint NOT NULL,
"team_id" uuid NOT NULL,
"created_at" timestamp (6) with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp (6) with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "team_portfolio_permissions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"team_id" uuid NOT NULL,
"portfolio_id" bigint NOT NULL,
"role" "role" NOT NULL,
"created_at" timestamp (6) with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp (6) with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "team" ADD CONSTRAINT "team_org_id_organisation_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organisation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "team_members" ADD CONSTRAINT "team_members_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "team_members" ADD CONSTRAINT "team_members_team_id_team_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."team"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "team_portfolio_permissions" ADD CONSTRAINT "team_portfolio_permissions_team_id_team_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."team"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "team_portfolio_permissions" ADD CONSTRAINT "team_portfolio_permissions_portfolio_id_portfolio_id_fk" FOREIGN KEY ("portfolio_id") REFERENCES "public"."portfolio"("id") ON DELETE no action ON UPDATE no action;

File diff suppressed because it is too large Load diff

View file

@ -1093,6 +1093,13 @@
"when": 1772637615885,
"tag": "0155_calm_hydra",
"breakpoints": true
},
{
"idx": 156,
"version": "7",
"when": 1774015417999,
"tag": "0156_light_shinko_yamashiro",
"breakpoints": true
}
]
}

View file

@ -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<typeof organisation, "select">;
export type NewOrganisation = InferModel<typeof organisation, "insert">;

59
src/app/db/schema/team.ts Normal file
View file

@ -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<typeof team, "select">;
export type NewTeam = InferModel<typeof team, "insert">;
export type TeamMembers = InferModel<typeof teamMembers, "select">;
export type NewTeamMembers = InferModel<typeof teamMembers, "insert">;
export type TeamPortfolioPermissions = InferModel<
typeof teamPortfolioPermissions,
"select"
>;
export type NewTeamPortfolioPermissions = InferModel<
typeof teamPortfolioPermissions,
"insert"
>;