mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
Merge pull request #264 from Hestia-Homes/feature/db-migrations-0197
adding index to allow multiple organidations to be mapped to a project
This commit is contained in:
commit
28735205fb
9 changed files with 18829 additions and 4 deletions
2
src/app/db/migrations/0197_bumpy_firebird.sql
Normal file
2
src/app/db/migrations/0197_bumpy_firebird.sql
Normal 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");
|
||||
1
src/app/db/migrations/0198_panoramic_triathlon.sql
Normal file
1
src/app/db/migrations/0198_panoramic_triathlon.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE "magic_plan_plan" ADD COLUMN "magic_plan_uid" text;
|
||||
9381
src/app/db/migrations/meta/0197_snapshot.json
Normal file
9381
src/app/db/migrations/meta/0197_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
9387
src/app/db/migrations/meta/0198_snapshot.json
Normal file
9387
src/app/db/migrations/meta/0198_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1380,6 +1380,20 @@
|
|||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -7,5 +7,6 @@ export const magicPlanPlan = pgTable(
|
|||
name: text("name"),
|
||||
address: text("address"),
|
||||
postcode: text("postcode"),
|
||||
magicPlanUid: text("magic_plan_uid"),
|
||||
},
|
||||
);
|
||||
37
src/app/db/schema/pibi_requests.ts
Normal file
37
src/app/db/schema/pibi_requests.ts
Normal 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;
|
||||
|
|
@ -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">;
|
||||
|
|
|
|||
|
|
@ -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" })
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue