2025-05-16 15:54:17 +02:00
|
|
|
import { pgTable, text, boolean, uuid, timestamp } from "drizzle-orm/pg-core";
|
|
|
|
|
import { relations } from "drizzle-orm";
|
2025-08-29 15:31:23 +02:00
|
|
|
import { Organization, organization } from "./03_organization";
|
2025-05-16 15:54:17 +02:00
|
|
|
import { createSelectSchema } from "drizzle-zod";
|
|
|
|
|
import { z } from "zod";
|
2025-08-29 15:31:23 +02:00
|
|
|
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),
|
2025-08-29 15:31:23 +02:00
|
|
|
...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;
|
|
|
|
|
};
|