mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Create join tables for things that can connect to games.
This commit is contained in:
parent
30cd8ceb97
commit
e229fd9b1c
4 changed files with 1482 additions and 29 deletions
24
drizzle/0001_dapper_spiral.sql
Normal file
24
drizzle/0001_dapper_spiral.sql
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
CREATE TABLE `artists_to_games` (
|
||||||
|
`artist_id` varchar(255),
|
||||||
|
`game_id` varchar(255)
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE `categories_to_games` (
|
||||||
|
`category_id` varchar(255),
|
||||||
|
`game_id` varchar(255)
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE `designers_to_games` (
|
||||||
|
`designer_id` varchar(255),
|
||||||
|
`game_id` varchar(255)
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE `mechanics_to_games` (
|
||||||
|
`mechanic_id` varchar(255),
|
||||||
|
`game_id` varchar(255)
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE `publishers_to_games` (
|
||||||
|
`publisher_id` varchar(255),
|
||||||
|
`game_id` varchar(255)
|
||||||
|
);
|
||||||
1233
drizzle/meta/0001_snapshot.json
Normal file
1233
drizzle/meta/0001_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -8,6 +8,13 @@
|
||||||
"when": 1707012854588,
|
"when": 1707012854588,
|
||||||
"tag": "0000_smooth_thunderbolt",
|
"tag": "0000_smooth_thunderbolt",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 1,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1707097761920,
|
||||||
|
"tag": "0001_dapper_spiral",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
247
src/schema.ts
247
src/schema.ts
|
|
@ -1,4 +1,4 @@
|
||||||
import { sql } from 'drizzle-orm';
|
import { relations, sql } from 'drizzle-orm';
|
||||||
import { mysqlTable, datetime, varchar, boolean, timestamp, year, int, text } from 'drizzle-orm/mysql-core';
|
import { mysqlTable, datetime, varchar, boolean, timestamp, year, int, text } from 'drizzle-orm/mysql-core';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
|
|
||||||
|
|
@ -52,7 +52,9 @@ export const users = mysqlTable("users", {
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const user_relations = relations(users, ({ many }) => ({
|
||||||
|
user_roles: many(user_roles)
|
||||||
|
}));
|
||||||
|
|
||||||
// model Session {
|
// model Session {
|
||||||
// id String @id @unique
|
// id String @id @unique
|
||||||
|
|
@ -118,7 +120,7 @@ export const roles = mysqlTable("roles", {
|
||||||
// @@map("user_roles")
|
// @@map("user_roles")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
export const userRoles = mysqlTable("user_roles", {
|
export const user_roles = mysqlTable("user_roles", {
|
||||||
id: varchar("id", {
|
id: varchar("id", {
|
||||||
length: 255
|
length: 255
|
||||||
}).primaryKey()
|
}).primaryKey()
|
||||||
|
|
@ -137,6 +139,17 @@ export const userRoles = mysqlTable("user_roles", {
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const user_role_relations = relations(user_roles, ({ one }) => ({
|
||||||
|
role: one(roles, {
|
||||||
|
fields: [user_roles.roleId],
|
||||||
|
references: [roles.id]
|
||||||
|
}),
|
||||||
|
user: one(users, {
|
||||||
|
fields: [user_roles.userId],
|
||||||
|
references: [users.id]
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
// model Game {
|
// model Game {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
// name String
|
// name String
|
||||||
|
|
@ -206,7 +219,15 @@ export const games = mysqlTable("games", {
|
||||||
lastSyncAt: datetime("last_sync_at"),
|
lastSyncAt: datetime("last_sync_at"),
|
||||||
createdAt: datetime("created_at").default(sql`(now(6))`),
|
createdAt: datetime("created_at").default(sql`(now(6))`),
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
export const gameRelations = relations(games, ({ many }) => ({
|
||||||
|
categories_to_games: many(categories_to_games),
|
||||||
|
mechanics_to_games: many(mechanics_to_games),
|
||||||
|
designers_to_games: many(designers_to_games),
|
||||||
|
publishers_to_games: many(publishers_to_games),
|
||||||
|
artists_to_games: many(artists_to_games),
|
||||||
|
}))
|
||||||
|
|
||||||
// model Expansion {
|
// model Expansion {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
|
|
@ -241,6 +262,17 @@ export const expansions = mysqlTable("expansions", {
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const expansion_relations = relations(expansions, ({ one }) => ({
|
||||||
|
baseGame: one(games, {
|
||||||
|
fields: [expansions.baseGameId],
|
||||||
|
references: [games.id]
|
||||||
|
}),
|
||||||
|
game: one(games, {
|
||||||
|
fields: [expansions.gameId],
|
||||||
|
references: [games.id]
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
// model Collection {
|
// model Collection {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
// user_id String @unique
|
// user_id String @unique
|
||||||
|
|
@ -263,7 +295,14 @@ export const collections = mysqlTable("collections", {
|
||||||
.references(() => users.id, { onDelete: 'cascade' }),
|
.references(() => users.id, { onDelete: 'cascade' }),
|
||||||
createdAt: datetime("created_at").default(sql`(now(6))`),
|
createdAt: datetime("created_at").default(sql`(now(6))`),
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
export const collection_relations = relations(collections, ({ one }) => ({
|
||||||
|
user: one(users, {
|
||||||
|
fields: [collections.userId],
|
||||||
|
references: [users.id]
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
// model CollectionItem {
|
// model CollectionItem {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
|
|
@ -279,7 +318,7 @@ export const collections = mysqlTable("collections", {
|
||||||
// @@map("collection_items")
|
// @@map("collection_items")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
export const collectionItems = mysqlTable("collection_items", {
|
export const collection_items = mysqlTable("collection_items", {
|
||||||
id: varchar("id", {
|
id: varchar("id", {
|
||||||
length: 255
|
length: 255
|
||||||
}).primaryKey()
|
}).primaryKey()
|
||||||
|
|
@ -296,7 +335,18 @@ export const collectionItems = mysqlTable("collection_items", {
|
||||||
.references(() => games.id, { onDelete: 'cascade' }),
|
.references(() => games.id, { onDelete: 'cascade' }),
|
||||||
createdAt: datetime("created_at").default(sql`(now(6))`),
|
createdAt: datetime("created_at").default(sql`(now(6))`),
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
export const collection_item_relations = relations(collection_items, ({ one }) =>({
|
||||||
|
collection: one(collections, {
|
||||||
|
fields: [collection_items.collectionId],
|
||||||
|
references: [collections.id]
|
||||||
|
}),
|
||||||
|
game: one(games, {
|
||||||
|
fields: [collection_items.gameId],
|
||||||
|
references: [games.id]
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
// model Wishlist {
|
// model Wishlist {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
|
|
@ -322,6 +372,13 @@ export const wishlists = mysqlTable("wishlists", {
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const wishlists_relations = relations(wishlists, ({ one }) => ({
|
||||||
|
user: one(users, {
|
||||||
|
fields: [wishlists.userId],
|
||||||
|
references: [users.id]
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
// model WishlistItem {
|
// model WishlistItem {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
// wishlist_id String
|
// wishlist_id String
|
||||||
|
|
@ -337,25 +394,37 @@ export const wishlists = mysqlTable("wishlists", {
|
||||||
// @@map("wishlist_items")
|
// @@map("wishlist_items")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
export const wishlistItems = mysqlTable("wishlist_items", {
|
export const wishlist_items = mysqlTable('wishlist_items', {
|
||||||
id: varchar("id", {
|
id: varchar('id', {
|
||||||
length: 255
|
length: 255
|
||||||
}).primaryKey()
|
})
|
||||||
.$defaultFn(() => nanoid()),
|
.primaryKey()
|
||||||
wishlistId: varchar("wishlist_id", {
|
.$defaultFn(() => nanoid()),
|
||||||
length: 255
|
wishlistId: varchar('wishlist_id', {
|
||||||
})
|
length: 255
|
||||||
.notNull()
|
})
|
||||||
.references(() => wishlists.id, { onDelete: 'cascade' }),
|
.notNull()
|
||||||
gameId: varchar("game_id", {
|
.references(() => wishlists.id, { onDelete: 'cascade' }),
|
||||||
length: 255
|
gameId: varchar('game_id', {
|
||||||
})
|
length: 255
|
||||||
.notNull()
|
})
|
||||||
.references(() => games.id, { onDelete: 'cascade' }),
|
.notNull()
|
||||||
createdAt: datetime("created_at").default(sql`(now(6))`),
|
.references(() => games.id, { onDelete: 'cascade' }),
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
createdAt: datetime('created_at').default(sql`(now(6))`),
|
||||||
|
updatedAt: datetime('updated_at').default(sql`(now(6))`)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const wishlist_item_relations = relations(wishlist_items, ({ one }) => ({
|
||||||
|
wishlist: one(wishlists, {
|
||||||
|
fields: [wishlist_items.wishlistId],
|
||||||
|
references: [wishlists.id]
|
||||||
|
}),
|
||||||
|
game: one(games, {
|
||||||
|
fields: [wishlist_items.gameId],
|
||||||
|
references: [games.id]
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
|
||||||
// model List {
|
// model List {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
// name String
|
// name String
|
||||||
|
|
@ -422,7 +491,11 @@ export const publishers = mysqlTable("publishers", {
|
||||||
externalId: int("external_id"),
|
externalId: int("external_id"),
|
||||||
createdAt: datetime("created_at").default(sql`(now(6))`),
|
createdAt: datetime("created_at").default(sql`(now(6))`),
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
export const publishers_relations = relations(publishers, ({ many }) => ({
|
||||||
|
publishers_to_games: many(publishers_to_games)
|
||||||
|
}));
|
||||||
|
|
||||||
// model Category {
|
// model Category {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
|
|
@ -451,7 +524,11 @@ export const categories = mysqlTable("categories", {
|
||||||
externalId: int("external_id"),
|
externalId: int("external_id"),
|
||||||
createdAt: datetime("created_at").default(sql`(now(6))`),
|
createdAt: datetime("created_at").default(sql`(now(6))`),
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
export const categories_relations = relations(categories, ({ many }) => ({
|
||||||
|
categories_to_games: many(categories_to_games)
|
||||||
|
}));
|
||||||
|
|
||||||
// model Mechanic {
|
// model Mechanic {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
|
|
@ -480,7 +557,11 @@ export const mechanics = mysqlTable("mechanics", {
|
||||||
externalId: int("external_id"),
|
externalId: int("external_id"),
|
||||||
createdAt: datetime("created_at").default(sql`(now(6))`),
|
createdAt: datetime("created_at").default(sql`(now(6))`),
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
export const mechanic_relations = relations(mechanics, ({ many }) => ({
|
||||||
|
mechanics_to_games: many(mechanics_to_games)
|
||||||
|
}))
|
||||||
|
|
||||||
// model Designer {
|
// model Designer {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
|
|
@ -509,7 +590,11 @@ export const designers = mysqlTable("designers", {
|
||||||
externalId: int("external_id"),
|
externalId: int("external_id"),
|
||||||
createdAt: datetime("created_at").default(sql`(now(6))`),
|
createdAt: datetime("created_at").default(sql`(now(6))`),
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
export const designers_relations = relations(designers, ({ many }) => ({
|
||||||
|
designers_to_games: many(designers_to_games)
|
||||||
|
}));
|
||||||
|
|
||||||
// model Artist {
|
// model Artist {
|
||||||
// id String @id @default(cuid())
|
// id String @id @default(cuid())
|
||||||
|
|
@ -538,4 +623,108 @@ export const artists = mysqlTable("artists", {
|
||||||
externalId: int("external_id"),
|
externalId: int("external_id"),
|
||||||
createdAt: datetime("created_at").default(sql`(now(6))`),
|
createdAt: datetime("created_at").default(sql`(now(6))`),
|
||||||
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
updatedAt: datetime("updated_at").default(sql`(now(6))`)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
export const artists_relations = relations(artists, ({ many }) => ({
|
||||||
|
artists_to_games: many(artists_to_games)
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const artists_to_games = mysqlTable('artists_to_games', {
|
||||||
|
artistId: varchar('artist_id', {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
gameId: varchar('game_id', {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const artists_to_games_relations = relations(artists_to_games, ({ one }) => ({
|
||||||
|
artist: one(artists, {
|
||||||
|
fields: [artists_to_games.artistId],
|
||||||
|
references: [artists.id]
|
||||||
|
}),
|
||||||
|
game: one(games, {
|
||||||
|
fields: [artists_to_games.gameId],
|
||||||
|
references: [games.id]
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const categories_to_games = mysqlTable("categories_to_games", {
|
||||||
|
categoryId: varchar("category_id", {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
gameId: varchar("game_id", {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const categories_to_games_relations = relations(categories_to_games, ({ one }) => ({
|
||||||
|
category: one(categories, {
|
||||||
|
fields: [categories_to_games.categoryId],
|
||||||
|
references: [categories.id]
|
||||||
|
}),
|
||||||
|
game: one(games, {
|
||||||
|
fields: [categories_to_games.gameId],
|
||||||
|
references: [games.id]
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
|
export const designers_to_games = mysqlTable("designers_to_games", {
|
||||||
|
designerId: varchar("designer_id", {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
gameId: varchar("game_id", {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const designers_to_games_relations = relations(designers_to_games, ({ one }) => ({
|
||||||
|
designer: one(designers, {
|
||||||
|
fields: [designers_to_games.designerId],
|
||||||
|
references: [designers.id]
|
||||||
|
}),
|
||||||
|
game: one(games, {
|
||||||
|
fields: [designers_to_games.gameId],
|
||||||
|
references: [games.id]
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
|
export const mechanics_to_games = mysqlTable("mechanics_to_games", {
|
||||||
|
mechanicId: varchar("mechanic_id", {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
gameId: varchar("game_id", {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const mechanics_to_games_relations = relations(mechanics_to_games, ({ one }) => ({
|
||||||
|
mechanic: one(mechanics, {
|
||||||
|
fields: [mechanics_to_games.mechanicId],
|
||||||
|
references: [mechanics.id]
|
||||||
|
}),
|
||||||
|
game: one(games, {
|
||||||
|
fields: [mechanics_to_games.gameId],
|
||||||
|
references: [games.id]
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const publishers_to_games = mysqlTable("publishers_to_games", {
|
||||||
|
publisherId: varchar("publisher_id", {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
gameId: varchar("game_id", {
|
||||||
|
length: 255
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const publishers_to_games_relations = relations(publishers_to_games, ({ one }) => ({
|
||||||
|
publisher: one(publishers, {
|
||||||
|
fields: [publishers_to_games.publisherId],
|
||||||
|
references: [publishers.id]
|
||||||
|
}),
|
||||||
|
game: one(games, {
|
||||||
|
fields: [publishers_to_games.gameId],
|
||||||
|
references: [games.id]
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue