Files
gregorlohaus.com/src/server/dbschema/schema.ts
2025-09-03 22:04:56 +02:00

87 lines
2.6 KiB
TypeScript

// Example model schema from the Drizzle docs
// https://orm.drizzle.team/docs/sql-schema-declaration
import { relations, sql } from "drizzle-orm";
import { index, pgEnum, pgSchema, pgTableCreator } from "drizzle-orm/pg-core";
/**
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
* database instance for multiple projects.
*
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
*/
export const createTable = pgTableCreator((name) => `gregorlohaus.com_${name}`);
export const layoutPositionEnum = pgEnum('layout_position',['sidebar','header','col1','col2'])
export const cvCategory = createTable(
"cv_category",
(d) => ({
id: d.uuid().primaryKey(),
name: d.varchar({length: 50}),
layoutPosition: layoutPositionEnum()
}),
(t) => [index("name_idx").on(t.name)],
)
export const cvCategoryRelations = relations(cvCategory,({many}) => ({
cvEntry: many(cvEntry)
}))
export const cvEntry = createTable(
"cv_entry",
(d) => ({
id: d.uuid().primaryKey().notNull(),
categoryId: d.uuid('category_id'),
fromTime: d.timestamp().notNull().$type<Date>(),
toTime: d.timestamp().notNull().$type<Date>(),
title: d.varchar({length:50}).notNull(),
description: d.text(),
hideDates: d.boolean(),
createdAt: d
.timestamp({ withTimezone: true })
.default(sql`CURRENT_TIMESTAMP`)
.notNull().$type<Date>(),
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()).$type<Date>(),
})
)
export const cvEntryRelations = relations(cvEntry, ({one}) => ({
category: one(cvCategory, {
fields: [cvEntry.categoryId],
references: [cvCategory.id]
}),
}));
export const sourceTypeEnum = pgEnum('source_type',['open','closed'])
export const releaseStatus = pgEnum('release_status',['released','unreleased'])
export const stackItemEnum = pgEnum('stack_item',['drizzle','postgres','nextjs','react','servercomponents','php','laravel','reactnative','expo','mysql','nginx','protobuf','grpc'])
export const project = createTable(
"project",
(d) => ({
id: d.uuid().primaryKey().notNull(),
title: d.varchar({length: 50}).notNull(),
sourceType: sourceTypeEnum(),
sourceLink: d.varchar({length: 200}),
releaseStatus: releaseStatus(),
releaseLink: d.varchar({length: 200}),
stackId: d.uuid(),
})
)
export const projectRelations = relations(project, ({one}) => ({
techStack: one(techStack, {
fields: [project.stackId],
references: [techStack.id],
})
}))
export const techStack = createTable(
"tech_stack",
(d) => ({
id: d.uuid().primaryKey().notNull(),
stackItems: stackItemEnum().array()
})
)