2024-11-06 17:49:18 +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';
|
2024-07-25 00:39:03 +00:00
|
|
|
|
2024-08-07 17:01:38 +00:00
|
|
|
export const publishers_to_games = pgTable(
|
2024-07-25 00:39:03 +00:00
|
|
|
'publishers_to_games',
|
|
|
|
|
{
|
2024-11-06 17:49:18 +00:00
|
|
|
publisher_id: uuid()
|
2024-07-25 00:39:03 +00:00
|
|
|
.notNull()
|
2024-09-04 23:04:41 +00:00
|
|
|
.references(() => publishersTable.id, { onDelete: 'restrict', onUpdate: 'cascade' }),
|
2024-11-06 17:49:18 +00:00
|
|
|
game_id: uuid()
|
2024-07-25 00:39:03 +00:00
|
|
|
.notNull()
|
2024-09-04 23:04:41 +00:00
|
|
|
.references(() => gamesTable.id, { onDelete: 'restrict', onUpdate: 'cascade' }),
|
2024-07-25 00:39:03 +00:00
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
|
|
|
|
publishersToGamesPkey: primaryKey({
|
|
|
|
|
columns: [table.publisher_id, table.game_id],
|
|
|
|
|
}),
|
2024-11-06 17:49:18 +00:00
|
|
|
};
|
2024-07-25 00:39:03 +00:00
|
|
|
},
|
2024-11-06 17:49:18 +00:00
|
|
|
);
|
2024-07-25 00:39:03 +00:00
|
|
|
|
|
|
|
|
export const publishers_to_games_relations = relations(publishers_to_games, ({ one }) => ({
|
2024-09-04 23:04:41 +00:00
|
|
|
publisher: one(publishersTable, {
|
2024-07-25 00:39:03 +00:00
|
|
|
fields: [publishers_to_games.publisher_id],
|
2024-09-04 23:04:41 +00:00
|
|
|
references: [publishersTable.id],
|
2024-07-25 00:39:03 +00:00
|
|
|
}),
|
2024-09-04 23:04:41 +00:00
|
|
|
game: one(gamesTable, {
|
2024-07-25 00:39:03 +00:00
|
|
|
fields: [publishers_to_games.game_id],
|
2024-09-04 23:04:41 +00:00
|
|
|
references: [gamesTable.id],
|
2024-07-25 00:39:03 +00:00
|
|
|
}),
|
2024-11-06 17:49:18 +00:00
|
|
|
}));
|