Blame · Line-by-line history
schema-extensions.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 45e31d0 | 1 | /** |
| 2 | * Extended database schema — branch protection, status checks, | |
| 3 | * notifications, organizations, and teams. | |
| 4 | * | |
| 5 | * These extend the base schema to add enterprise-grade features. | |
| 6 | */ | |
| 7 | ||
| 8 | import { | |
| 9 | pgTable, | |
| 10 | text, | |
| 11 | timestamp, | |
| 12 | uuid, | |
| 13 | boolean, | |
| 14 | integer, | |
| 15 | uniqueIndex, | |
| 16 | index, | |
| 17 | serial, | |
| 18 | jsonb, | |
| 19 | } from "drizzle-orm/pg-core"; | |
| 20 | import { users, repositories } from "./schema"; | |
| 21 | ||
| 22 | // ─── Branch Protection Rules ──────────────────────────────────────────────── | |
| 23 | ||
| 24 | ||
| 25 | // ─── Status Checks (CI Integration) ──────────────────────────────────────── | |
| 26 | ||
| 27 | export const statusChecks = pgTable( | |
| 28 | "status_checks", | |
| 29 | { | |
| 30 | id: uuid("id").primaryKey().defaultRandom(), | |
| 31 | repositoryId: uuid("repository_id") | |
| 32 | .notNull() | |
| 33 | .references(() => repositories.id, { onDelete: "cascade" }), | |
| 34 | commitSha: text("commit_sha").notNull(), | |
| 35 | context: text("context").notNull(), // e.g. "ci/build", "gatetest/scan" | |
| 36 | state: text("state").notNull().default("pending"), // pending, success, failure, error | |
| 37 | description: text("description"), | |
| 38 | targetUrl: text("target_url"), // link to CI build | |
| 39 | createdBy: text("created_by"), // token name or integration name | |
| 40 | createdAt: timestamp("created_at").defaultNow().notNull(), | |
| 41 | updatedAt: timestamp("updated_at").defaultNow().notNull(), | |
| 42 | }, | |
| 43 | (table) => [ | |
| 44 | index("status_checks_repo_sha").on(table.repositoryId, table.commitSha), | |
| 45 | index("status_checks_repo_context").on(table.repositoryId, table.context), | |
| 46 | ] | |
| 47 | ); | |
| 48 | ||
| 49 | // ─── Notifications ────────────────────────────────────────────────────────── | |
| 50 | ||
| 51 | ||
| 52 | // ─── Organizations ────────────────────────────────────────────────────────── | |
| 53 | ||
| 45ac593 | 54 | /** |
| 55 | * Organizations lives in schema.ts — re-exported here so the historical | |
| 56 | * import path keeps working. | |
| 57 | * | |
| 58 | * This file used to declare its OWN pgTable("organizations") with a different | |
| 59 | * column set: display_name/website/location/is_verified but no `slug` and no | |
| 60 | * `created_by_id`. Two Drizzle objects, one physical table, irreconcilable | |
| 61 | * shapes. drizzle.config.ts only includes schema.ts and deploys run | |
| 62 | * db:migrate (never db:push), so this definition was never migrated — it | |
| 63 | * described a table that has never existed. Every insert through it wrote | |
| 64 | * columns Postgres does not have while omitting two NOT NULL columns, which | |
| 65 | * is why POST /orgs/new could never succeed. | |
| 66 | * | |
| 67 | * Migration 0113 adds the four extra columns to the real table so nothing the | |
| 68 | * create form collects is discarded. Keeping ONE definition is what stops the | |
| 69 | * two drifting apart again. | |
| 70 | */ | |
| 71 | import { | |
| 72 | organizations, | |
| 73 | orgMembers, | |
| 74 | teams, | |
| 75 | teamMembers, | |
| 76 | teamRepos, | |
| 77 | branchProtection, | |
| 78 | notifications, | |
| 79 | } from "./schema"; | |
| 80 | export { | |
| 81 | organizations, | |
| 82 | orgMembers, | |
| 83 | teams, | |
| 84 | teamMembers, | |
| 85 | teamRepos, | |
| 86 | branchProtection, | |
| 87 | notifications, | |
| 88 | }; | |
| 45e31d0 | 89 | |
| 90 | ||
| 91 | // ─── Type Exports ─────────────────────────────────────────────────────────── | |
| 92 | ||
| 93 | export type BranchProtectionRule = typeof branchProtection.$inferSelect; | |
| 94 | export type StatusCheck = typeof statusChecks.$inferSelect; | |
| 95 | export type Notification = typeof notifications.$inferSelect; | |
| 96 | export type Organization = typeof organizations.$inferSelect; | |
| 97 | export type OrgMember = typeof orgMembers.$inferSelect; | |
| 98 | export type Team = typeof teams.$inferSelect; | |
| 99 | export type TeamMember = typeof teamMembers.$inferSelect; |