add schema files and migration 0198 for magic_plan_uid

This commit is contained in:
Khalim Conn-Kowlessar 2026-05-07 18:13:17 +00:00
parent 00e22a15e9
commit 4357ae9802
7 changed files with 9440 additions and 5 deletions

View file

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

File diff suppressed because it is too large Load diff

View file

@ -1387,6 +1387,13 @@
"when": 1778157212969,
"tag": "0197_bumpy_firebird",
"breakpoints": true
},
{
"idx": 198,
"version": "7",
"when": 1778176651140,
"tag": "0198_panoramic_triathlon",
"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" })