Skip to content
File

Blob: src/worker/db/d1/schema/namespaces.ts

typescript20 lines
1import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
2 
3import { 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`.
9export 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 
18export type NamespaceRow = typeof namespaces.$inferSelect;
19export type NewNamespaceRow = typeof namespaces.$inferInsert;