boredgame/src/lib/server/api/databases/tables/publishersToGames.table.ts

35 lines
995 B
TypeScript
Raw Normal View History

2024-09-04 23:04:41 +00:00
import { relations } from 'drizzle-orm'
import { pgTable, primaryKey, uuid } from 'drizzle-orm/pg-core'
import { gamesTable } from '././games.table'
import { publishersTable } from './publishers.table'
export const publishers_to_games = pgTable(
'publishers_to_games',
{
publisher_id: uuid('publisher_id')
.notNull()
2024-09-04 23:04:41 +00:00
.references(() => publishersTable.id, { onDelete: 'restrict', onUpdate: 'cascade' }),
game_id: uuid('game_id')
.notNull()
2024-09-04 23:04:41 +00:00
.references(() => gamesTable.id, { onDelete: 'restrict', onUpdate: 'cascade' }),
},
(table) => {
return {
publishersToGamesPkey: primaryKey({
columns: [table.publisher_id, table.game_id],
}),
2024-09-04 23:04:41 +00:00
}
},
2024-09-04 23:04:41 +00:00
)
export const publishers_to_games_relations = relations(publishers_to_games, ({ one }) => ({
2024-09-04 23:04:41 +00:00
publisher: one(publishersTable, {
fields: [publishers_to_games.publisher_id],
2024-09-04 23:04:41 +00:00
references: [publishersTable.id],
}),
2024-09-04 23:04:41 +00:00
game: one(gamesTable, {
fields: [publishers_to_games.game_id],
2024-09-04 23:04:41 +00:00
references: [gamesTable.id],
}),
2024-09-04 23:04:41 +00:00
}))