mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
29 lines
911 B
TypeScript
29 lines
911 B
TypeScript
|
|
import { pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core';
|
||
|
|
import { createId as cuid2 } from '@paralleldrive/cuid2';
|
||
|
|
import { type InferSelectModel, relations } from 'drizzle-orm';
|
||
|
|
import users from './users';
|
||
|
|
|
||
|
|
const collections = pgTable('collections', {
|
||
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
||
|
|
cuid: text('cuid')
|
||
|
|
.unique()
|
||
|
|
.$defaultFn(() => cuid2()),
|
||
|
|
user_id: uuid('user_id')
|
||
|
|
.notNull()
|
||
|
|
.references(() => users.id, { onDelete: 'cascade' }),
|
||
|
|
name: text('name').notNull().default('My Collection'),
|
||
|
|
created_at: timestamp('created_at').notNull().defaultNow(),
|
||
|
|
updated_at: timestamp('updated_at').notNull().defaultNow(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const collection_relations = relations(collections, ({ one }) => ({
|
||
|
|
user: one(users, {
|
||
|
|
fields: [collections.user_id],
|
||
|
|
references: [users.id],
|
||
|
|
}),
|
||
|
|
}));
|
||
|
|
|
||
|
|
export type Collections = InferSelectModel<typeof collections>;
|
||
|
|
|
||
|
|
export default collections;
|