Open History to see the last commit
1import {
2 date,
3 index,
4 integer,
5 pgTable,
6 text,
7 unique,
8} from "drizzle-orm/pg-core";
9
10/**
11 Stores the creation timestamp in milliseconds since epoch.
12*/
13const createdAt = date("created_at", { mode: "date" }).notNull();
14
15export const usersTable = pgTable(
16 "users",
17 {
18 id: text().primaryKey().notNull(), // nanoid
19 name: text().notNull(),
20 age: integer().notNull(),
21 email: text().notNull(),
22 },
23 (users) => [
24 unique("users_email_unique_tempdbid").on(users.email),
25 // tenantEmailUnique: index("users_tenant_email_unique")
26 // .on(users.tempDbId, users.email)
27 // .unique(),
28 ],
29);
30
31export type UserRecord = typeof usersTable.$inferSelect;
32
33export const projectsTable = pgTable("projects", {
34 id: text().primaryKey(), // nanoid
35 name: text().notNull().unique(),
36 description: text().notNull(),
37 createdAt,
38});
39
40export type ProjectRecord = typeof projectsTable.$inferSelect;
41
42export const boardsTable = pgTable("boards", {
43 id: text().primaryKey(), // nanoid
44 name: text().notNull(),
45 description: text(),
46 createdAt,
47 projectId: text("project_id")
48 .references(() => projectsTable.id, { onDelete: "cascade" })
49 .notNull(),
50});
51
52export type BoardRecord = typeof boardsTable.$inferSelect;
53
54export const todoItemsTable = pgTable(
55 "todo_items",
56 {
57 id: text().primaryKey(), // nanoid
58 title: text().notNull(),
59 description: text(),
60 createdAt,
61 boardId: text("board_id")
62 .references(() => boardsTable.id, { onDelete: "cascade" })
63 .notNull(),
64 priority: integer().default(0),
65 position: text().notNull(),
66 },
67 (table) => [
68 index("todo_items_board_id_position_idx").on(table.boardId, table.position),
69 ],
70);
71
72export type TodoItemRecord = typeof todoItemsTable.$inferSelect;
73
74export const seedTable = pgTable("seed_script_runs", {
75 id: text().primaryKey(), // nanoid
76 createdAt,
77 // state: pgEnum("state", ["completed", "in_progress", "failed"])(),
78 // NOTE: pgEnum doesn't seem to work with pglite
79 state: text("state"),
80});