Create @workspace/schema package with Project and Task table definitions, Drizzle relations, Valibot validation schemas (select/insert/update), and wire as workspace dependency in API and Web apps.
28 lines
799 B
TypeScript
28 lines
799 B
TypeScript
import { pgTable, uuid, text, timestamp, check } from "drizzle-orm/pg-core";
|
|
import { sql } from "drizzle-orm";
|
|
import { PROJECT_STATUSES } from "./enums";
|
|
|
|
const projectStatusValues = PROJECT_STATUSES.map((s) => `'${s}'`).join(", ");
|
|
|
|
export const projects = pgTable(
|
|
"projects",
|
|
{
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
name: text("name").notNull(),
|
|
description: text("description"),
|
|
status: text("status").notNull().default("active"),
|
|
createdAt: timestamp("created_at", { mode: "string" })
|
|
.notNull()
|
|
.defaultNow(),
|
|
updatedAt: timestamp("updated_at", { mode: "string" })
|
|
.notNull()
|
|
.defaultNow(),
|
|
},
|
|
(table) => [
|
|
check(
|
|
"project_status_check",
|
|
sql`${table.status} IN (${sql.raw(projectStatusValues)})`,
|
|
),
|
|
],
|
|
);
|