banatie-service/packages/database/src/schema/projects.ts

31 lines
959 B
TypeScript

import { pgTable, uuid, text, timestamp, unique } from 'drizzle-orm/pg-core';
import { organizations } from './organizations';
export const projects = pgTable(
'projects',
{
id: uuid('id').primaryKey().defaultRandom(),
// Project details
name: text('name').notNull(),
slug: text('slug').notNull(), // URL-friendly identifier for storage paths
organizationId: uuid('organization_id')
.notNull()
.references(() => organizations.id, { onDelete: 'cascade' }),
// Timestamps
createdAt: timestamp('created_at').notNull().defaultNow(),
updatedAt: timestamp('updated_at')
.notNull()
.defaultNow()
.$onUpdate(() => new Date()),
},
(table) => ({
// Unique constraint: one project slug per organization
uniqueOrgProjectSlug: unique().on(table.organizationId, table.slug),
}),
);
export type Project = typeof projects.$inferSelect;
export type NewProject = typeof projects.$inferInsert;