File
Blob: src/worker/db/d1/schema/namespaces.ts
| 1 | import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; |
| 2 | |
| 3 | import { users } from "./users"; |
| 4 | |
| 5 | // A namespace owns repositories and is addressed in URLs as `/:owner` (the |
| 6 | // `:owner` segment equals `slug`). On first sign-in we may create one |
| 7 | // namespace whose slug equals the verified `preferred_username` claim, |
| 8 | // race-protected against concurrent claims via `ON CONFLICT DO NOTHING`. |
| 9 | export const namespaces = sqliteTable("namespaces", { |
| 10 | id: text("id").primaryKey(), |
| 11 | slug: text("slug").notNull().unique(), |
| 12 | createdBy: text("created_by") |
| 13 | .notNull() |
| 14 | .references(() => users.id, { onDelete: "restrict" }), |
| 15 | createdAt: integer("created_at").notNull(), |
| 16 | }); |
| 17 | |
| 18 | export type NamespaceRow = typeof namespaces.$inferSelect; |
| 19 | export type NewNamespaceRow = typeof namespaces.$inferInsert; |