Files
portabase/src/db/schema/06_project.ts
T

36 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-05-16 15:54:17 +02:00
import { pgTable, text, boolean, uuid, timestamp } from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm";
import { Organization, organization } from "./03_organization";
2025-05-16 15:54:17 +02:00
import { createSelectSchema } from "drizzle-zod";
import { z } from "zod";
import { Database, database } from "./07_database";
import {timestamps} from "@/db/schema/00_common";
2025-05-16 15:54:17 +02:00
export const project = pgTable("projects", {
id: uuid("id").primaryKey().defaultRandom(),
slug: text("slug").notNull().unique(),
name: text("name").notNull().notNull(),
isArchived: boolean("is_archived").default(false),
organizationId: uuid("organization_id")
.notNull()
.references(() => organization.id),
...timestamps
2025-05-16 15:54:17 +02:00
});
export const projectRelations = relations(project, ({ one, many }) => ({
organization: one(organization, {
fields: [project.organizationId],
references: [organization.id],
}),
databases: many(database),
}));
export const projectSchema = createSelectSchema(project);
export type Project = z.infer<typeof projectSchema>;
export type ProjectWith = Project & {
databases: Database[];
organization: Organization;
};