Merge branch 'main' into feature/magicplan-tables

This commit is contained in:
Daniel Roth 2026-05-12 15:41:20 +00:00
commit 3d1a35250f
14 changed files with 37633 additions and 4 deletions

View file

@ -0,0 +1,16 @@
CREATE TABLE "pibi_requests" (
"id" bigserial PRIMARY KEY NOT NULL,
"hubspot_deal_id" text NOT NULL,
"portfolio_id" bigint NOT NULL,
"measure_name" text NOT NULL,
"ordered_at" timestamp with time zone DEFAULT now() NOT NULL,
"completed_at" timestamp with time zone,
"created_by_user_id" bigint NOT NULL,
"pushed_at" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "survey_requests" ADD COLUMN "survey_type" text;--> statement-breakpoint
ALTER TABLE "pibi_requests" ADD CONSTRAINT "pibi_requests_portfolio_id_portfolio_id_fk" FOREIGN KEY ("portfolio_id") REFERENCES "public"."portfolio"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "pibi_requests" ADD CONSTRAINT "pibi_requests_created_by_user_id_user_id_fk" FOREIGN KEY ("created_by_user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_pibi_requests_deal_id" ON "pibi_requests" USING btree ("hubspot_deal_id");--> statement-breakpoint
CREATE INDEX "idx_pibi_requests_portfolio_id" ON "pibi_requests" USING btree ("portfolio_id");

View file

@ -0,0 +1,2 @@
ALTER TABLE "portfolio_organisation" DROP CONSTRAINT "portfolio_organisation_portfolio_id_unique";--> statement-breakpoint
ALTER TABLE "portfolio_organisation" ADD CONSTRAINT "portfolio_organisation_portfolio_id_organisation_id_unique" UNIQUE("portfolio_id","organisation_id");

View file

@ -0,0 +1 @@
ALTER TABLE "magic_plan_plan" ADD COLUMN "magic_plan_uid" text;

View file

@ -0,0 +1,2 @@
ALTER TYPE "public"."file_source" ADD VALUE 'magic_plan';--> statement-breakpoint
ALTER TYPE "public"."file_type" ADD VALUE 'magic_plan_json';

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1373,6 +1373,34 @@
"when": 1778078457355,
"tag": "0195_jittery_harry_osborn",
"breakpoints": true
},
{
"idx": 196,
"version": "7",
"when": 1778144686568,
"tag": "0196_fantastic_bastion",
"breakpoints": true
},
{
"idx": 197,
"version": "7",
"when": 1778157212969,
"tag": "0197_bumpy_firebird",
"breakpoints": true
},
{
"idx": 198,
"version": "7",
"when": 1778176651140,
"tag": "0198_panoramic_triathlon",
"breakpoints": true
},
{
"idx": 199,
"version": "7",
"when": 1778249728162,
"tag": "0199_rich_mandroid",
"breakpoints": true
}
]
}

View file

@ -7,5 +7,6 @@ export const magicPlanPlan = pgTable(
name: text("name"),
address: text("address"),
postcode: text("postcode"),
magicPlanUid: text("magic_plan_uid"),
},
);

View file

@ -0,0 +1,37 @@
import {
bigserial,
text,
timestamp,
pgTable,
bigint,
index,
} from "drizzle-orm/pg-core";
import { user } from "./users";
import { portfolio } from "./portfolio";
export const pibiRequests = pgTable(
"pibi_requests",
{
id: bigserial("id", { mode: "bigint" }).primaryKey(),
hubspotDealId: text("hubspot_deal_id").notNull(),
portfolioId: bigint("portfolio_id", { mode: "bigint" })
.notNull()
.references(() => portfolio.id),
measureName: text("measure_name").notNull(),
orderedAt: timestamp("ordered_at", { withTimezone: true })
.defaultNow()
.notNull(),
completedAt: timestamp("completed_at", { withTimezone: true }),
createdByUserId: bigint("created_by_user_id", { mode: "bigint" })
.notNull()
.references(() => user.id),
pushedAt: timestamp("pushed_at", { withTimezone: true }),
},
(table) => [
index("idx_pibi_requests_deal_id").on(table.hubspotDealId),
index("idx_pibi_requests_portfolio_id").on(table.portfolioId),
],
);
export type PibiRequest = typeof pibiRequests.$inferSelect;
export type NewPibiRequest = typeof pibiRequests.$inferInsert;

View file

@ -1,4 +1,4 @@
import { pgTable, bigint, uuid, timestamp } from "drizzle-orm/pg-core";
import { pgTable, bigint, uuid, timestamp, unique } from "drizzle-orm/pg-core";
import { portfolio } from "./portfolio";
import { organisation } from "./organisation";
import { InferModel } from "drizzle-orm";
@ -7,8 +7,7 @@ export const portfolioOrganisation = pgTable("portfolio_organisation", {
id: uuid("id").defaultRandom().primaryKey(),
portfolioId: bigint("portfolio_id", { mode: "bigint" })
.notNull()
.references(() => portfolio.id, { onDelete: "cascade" })
.unique(), // one organisation per portfolio
.references(() => portfolio.id, { onDelete: "cascade" }),
organisationId: uuid("organisation_id")
.notNull()
.references(() => organisation.id, { onDelete: "cascade" }),
@ -18,7 +17,9 @@ export const portfolioOrganisation = pgTable("portfolio_organisation", {
updatedAt: timestamp("updated_at", { precision: 6, withTimezone: true })
.defaultNow()
.notNull(),
});
}, (t) => ({
portfolioOrgUnique: unique().on(t.portfolioId, t.organisationId),
}));
export type PortfolioOrganisation = InferModel<typeof portfolioOrganisation, "select">;
export type NewPortfolioOrganisation = InferModel<typeof portfolioOrganisation, "insert">;

View file

@ -22,6 +22,7 @@ export const surveyRequests = pgTable(
.references(() => portfolio.id),
// Free-text notes from the requester describing what survey is needed.
notes: text("notes").notNull(),
surveyType: text("survey_type"),
// 'pending' | 'fulfilled'
status: text("status").notNull().default("pending"),
requestedBy: bigint("requested_by", { mode: "bigint" })

View file

@ -47,6 +47,8 @@ export const fileType = pgEnum("file_type", [
"installer_qualifications",
"installer_feedback",
"contractor_other",
// MagicPlan
"magic_plan_json"
]);
export const fileSource = pgEnum("file_source", [
@ -55,6 +57,7 @@ export const fileSource = pgEnum("file_source", [
"hubspot",
"ecmk",
"contractor",
"magic_plan"
]);
export const uploadedFiles = pgTable(