diff --git a/drizzle.config.ts b/drizzle.config.ts index e9ec449..117e93e 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -5,7 +5,11 @@ import { defineConfig } from 'drizzle-kit' export default defineConfig({ dialect: 'postgresql', out: './src/lib/server/api/databases/migrations', +<<<<<<< HEAD schema: './src/lib/server/api/databases/tables/*.table.ts', +======= + schema: './src/lib/server/api/databases/tables/index.ts', +>>>>>>> 5849219833a6b9a99ec24a960962c4c537e93748 dbCredentials: { host: env.DATABASE_HOST || 'localhost', port: Number(env.DATABASE_PORT) || 5432, diff --git a/src/lib/server/api/databases/tables/expansions.ts b/src/lib/server/api/databases/tables/expansions.ts new file mode 100644 index 0000000..a5ca59e --- /dev/null +++ b/src/lib/server/api/databases/tables/expansions.ts @@ -0,0 +1,32 @@ +import { createId as cuid2 } from '@paralleldrive/cuid2' +import { type InferSelectModel, relations } from 'drizzle-orm' +import { pgTable, text, uuid } from 'drizzle-orm/pg-core' +import { timestamps } from '../../common/utils/table.utils' +import { games } from './games' + +export const expansions = pgTable('expansions', { + id: uuid('id').primaryKey().defaultRandom(), + cuid: text('cuid') + .unique() + .$defaultFn(() => cuid2()), + base_game_id: uuid('base_game_id') + .notNull() + .references(() => games.id, { onDelete: 'restrict', onUpdate: 'cascade' }), + game_id: uuid('game_id') + .notNull() + .references(() => games.id, { onDelete: 'restrict', onUpdate: 'cascade' }), + ...timestamps, +}) + +export type Expansions = InferSelectModel + +export const expansion_relations = relations(expansions, ({ one }) => ({ + baseGame: one(games, { + fields: [expansions.base_game_id], + references: [games.id], + }), + game: one(games, { + fields: [expansions.game_id], + references: [games.id], + }), +})) diff --git a/src/lib/server/api/databases/tables/mechanics.ts b/src/lib/server/api/databases/tables/mechanics.ts new file mode 100644 index 0000000..f5d4ced --- /dev/null +++ b/src/lib/server/api/databases/tables/mechanics.ts @@ -0,0 +1,23 @@ +import { timestamps } from '../../common/utils/table.utils' +import { createId as cuid2 } from '@paralleldrive/cuid2' +import { type InferSelectModel, relations } from 'drizzle-orm' +import { pgTable, text, uuid } from 'drizzle-orm/pg-core' +import { mechanicsToExternalIds } from './mechanicsToExternalIds' +import { mechanics_to_games } from './mechanicsToGames' + +export const mechanics = pgTable('mechanics', { + id: uuid('id').primaryKey().defaultRandom(), + cuid: text('cuid') + .unique() + .$defaultFn(() => cuid2()), + name: text('name'), + slug: text('slug'), + ...timestamps, +}) + +export type Mechanics = InferSelectModel + +export const mechanics_relations = relations(mechanics, ({ many }) => ({ + mechanics_to_games: many(mechanics_to_games), + mechanicsToExternalIds: many(mechanicsToExternalIds), +})) diff --git a/src/lib/server/api/databases/tables/publishers.ts b/src/lib/server/api/databases/tables/publishers.ts new file mode 100644 index 0000000..3000625 --- /dev/null +++ b/src/lib/server/api/databases/tables/publishers.ts @@ -0,0 +1,23 @@ +import { timestamps } from '../../common/utils/table.utils' +import { createId as cuid2 } from '@paralleldrive/cuid2' +import { type InferSelectModel, relations } from 'drizzle-orm' +import { pgTable, text, uuid } from 'drizzle-orm/pg-core' +import { publishersToExternalIds } from './publishersToExternalIds' +import { publishers_to_games } from './publishersToGames' + +export const publishers = pgTable('publishers', { + id: uuid('id').primaryKey().defaultRandom(), + cuid: text('cuid') + .unique() + .$defaultFn(() => cuid2()), + name: text('name'), + slug: text('slug'), + ...timestamps, +}) + +export type Publishers = InferSelectModel + +export const publishers_relations = relations(publishers, ({ many }) => ({ + publishers_to_games: many(publishers_to_games), + publishersToExternalIds: many(publishersToExternalIds), +}))