Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
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.

schema-extensions.tsBlame99 lines · 2 contributors
45e31d0Claude1/**
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
8import {
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";
20import { users, repositories } from "./schema";
21
22// ─── Branch Protection Rules ────────────────────────────────────────────────
23
24
25// ─── Status Checks (CI Integration) ────────────────────────────────────────
26
27export 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
45ac593ccantynz-alt54/**
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 */
71import {
72 organizations,
73 orgMembers,
74 teams,
75 teamMembers,
76 teamRepos,
77 branchProtection,
78 notifications,
79} from "./schema";
80export {
81 organizations,
82 orgMembers,
83 teams,
84 teamMembers,
85 teamRepos,
86 branchProtection,
87 notifications,
88};
45e31d0Claude89
90
91// ─── Type Exports ───────────────────────────────────────────────────────────
92
93export type BranchProtectionRule = typeof branchProtection.$inferSelect;
94export type StatusCheck = typeof statusChecks.$inferSelect;
95export type Notification = typeof notifications.$inferSelect;
96export type Organization = typeof organizations.$inferSelect;
97export type OrgMember = typeof orgMembers.$inferSelect;
98export type Team = typeof teams.$inferSelect;
99export type TeamMember = typeof teamMembers.$inferSelect;