2024-05-08 00:19:13 +00:00
|
|
|
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 wishlists from './wishlists';
|
|
|
|
|
import games from './games';
|
|
|
|
|
|
|
|
|
|
const wishlist_items = pgTable('wishlist_items', {
|
|
|
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
|
|
|
cuid: text('cuid')
|
|
|
|
|
.unique()
|
|
|
|
|
.$defaultFn(() => cuid2()),
|
|
|
|
|
wishlist_id: uuid('wishlist_id')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => wishlists.id, { onDelete: 'cascade' }),
|
|
|
|
|
game_id: uuid('game_id')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => games.id, { onDelete: 'cascade' }),
|
2024-06-08 22:09:21 +00:00
|
|
|
created_at: timestamp('created_at', { mode: 'string' }).notNull().defaultNow(),
|
|
|
|
|
updated_at: timestamp('updated_at', { mode: 'string' }).notNull().defaultNow(),
|
2024-05-08 00:19:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type WishlistItems = InferSelectModel<typeof wishlist_items>;
|
|
|
|
|
|
|
|
|
|
export const wishlist_item_relations = relations(wishlist_items, ({ one }) => ({
|
|
|
|
|
wishlist: one(wishlists, {
|
|
|
|
|
fields: [wishlist_items.wishlist_id],
|
|
|
|
|
references: [wishlists.id],
|
|
|
|
|
}),
|
|
|
|
|
game: one(games, {
|
|
|
|
|
fields: [wishlist_items.game_id],
|
|
|
|
|
references: [games.id],
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
export default wishlist_items;
|