Fix connecting to localhost mysql version and not use planetscale adapters.

This commit is contained in:
Bradley Shellnut 2024-02-05 23:18:13 -08:00
parent e229fd9b1c
commit 3663fc328e
12 changed files with 244 additions and 358 deletions

View file

@ -6,6 +6,10 @@ export default defineConfig({
out: './drizzle', out: './drizzle',
driver: 'mysql2', driver: 'mysql2',
dbCredentials: { dbCredentials: {
uri: `${process.env.DATABASE_URL}` host: process.env.DATABASE_HOST || 'localhost',
port: 3306,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE || 'nut-shells'
} }
}); });

View file

@ -8,6 +8,11 @@ CREATE TABLE `artists` (
CONSTRAINT `artists_id` PRIMARY KEY(`id`) CONSTRAINT `artists_id` PRIMARY KEY(`id`)
); );
--> statement-breakpoint --> statement-breakpoint
CREATE TABLE `artists_to_games` (
`artist_id` varchar(255),
`game_id` varchar(255)
);
--> statement-breakpoint
CREATE TABLE `categories` ( CREATE TABLE `categories` (
`id` varchar(255) NOT NULL, `id` varchar(255) NOT NULL,
`name` varchar(255), `name` varchar(255),
@ -18,6 +23,11 @@ CREATE TABLE `categories` (
CONSTRAINT `categories_id` PRIMARY KEY(`id`) CONSTRAINT `categories_id` PRIMARY KEY(`id`)
); );
--> statement-breakpoint --> statement-breakpoint
CREATE TABLE `categories_to_games` (
`category_id` varchar(255),
`game_id` varchar(255)
);
--> statement-breakpoint
CREATE TABLE `collection_items` ( CREATE TABLE `collection_items` (
`id` varchar(255) NOT NULL, `id` varchar(255) NOT NULL,
`collection_id` varchar(255) NOT NULL, `collection_id` varchar(255) NOT NULL,
@ -45,6 +55,11 @@ CREATE TABLE `designers` (
CONSTRAINT `designers_id` PRIMARY KEY(`id`) CONSTRAINT `designers_id` PRIMARY KEY(`id`)
); );
--> statement-breakpoint --> statement-breakpoint
CREATE TABLE `designers_to_games` (
`designer_id` varchar(255),
`game_id` varchar(255)
);
--> statement-breakpoint
CREATE TABLE `expansions` ( CREATE TABLE `expansions` (
`id` varchar(255) NOT NULL, `id` varchar(255) NOT NULL,
`base_game_id` varchar(255) NOT NULL, `base_game_id` varchar(255) NOT NULL,
@ -87,6 +102,11 @@ CREATE TABLE `mechanics` (
CONSTRAINT `mechanics_id` PRIMARY KEY(`id`) CONSTRAINT `mechanics_id` PRIMARY KEY(`id`)
); );
--> statement-breakpoint --> statement-breakpoint
CREATE TABLE `mechanics_to_games` (
`mechanic_id` varchar(255),
`game_id` varchar(255)
);
--> statement-breakpoint
CREATE TABLE `publishers` ( CREATE TABLE `publishers` (
`id` varchar(255) NOT NULL, `id` varchar(255) NOT NULL,
`name` varchar(255), `name` varchar(255),
@ -97,6 +117,11 @@ CREATE TABLE `publishers` (
CONSTRAINT `publishers_id` PRIMARY KEY(`id`) CONSTRAINT `publishers_id` PRIMARY KEY(`id`)
); );
--> statement-breakpoint --> statement-breakpoint
CREATE TABLE `publishers_to_games` (
`publisher_id` varchar(255),
`game_id` varchar(255)
);
--> statement-breakpoint
CREATE TABLE `roles` ( CREATE TABLE `roles` (
`id` varchar(255) NOT NULL, `id` varchar(255) NOT NULL,
`name` varchar(255), `name` varchar(255),
@ -107,8 +132,6 @@ CREATE TABLE `roles` (
CREATE TABLE `sessions` ( CREATE TABLE `sessions` (
`id` varchar(255) NOT NULL, `id` varchar(255) NOT NULL,
`user_id` varchar(255) NOT NULL, `user_id` varchar(255) NOT NULL,
`ip_country` varchar(255),
`ip_address` varchar(255),
`expires_at` datetime NOT NULL, `expires_at` datetime NOT NULL,
CONSTRAINT `sessions_id` PRIMARY KEY(`id`) CONSTRAINT `sessions_id` PRIMARY KEY(`id`)
); );
@ -161,7 +184,7 @@ ALTER TABLE `collection_items` ADD CONSTRAINT `collection_items_game_id_games_id
ALTER TABLE `collections` ADD CONSTRAINT `collections_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE `collections` ADD CONSTRAINT `collections_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `expansions` ADD CONSTRAINT `expansions_base_game_id_games_id_fk` FOREIGN KEY (`base_game_id`) REFERENCES `games`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE `expansions` ADD CONSTRAINT `expansions_base_game_id_games_id_fk` FOREIGN KEY (`base_game_id`) REFERENCES `games`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `expansions` ADD CONSTRAINT `expansions_game_id_games_id_fk` FOREIGN KEY (`game_id`) REFERENCES `games`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE `expansions` ADD CONSTRAINT `expansions_game_id_games_id_fk` FOREIGN KEY (`game_id`) REFERENCES `games`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `sessions` ADD CONSTRAINT `sessions_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE `sessions` ADD CONSTRAINT `sessions_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `user_roles` ADD CONSTRAINT `user_roles_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE `user_roles` ADD CONSTRAINT `user_roles_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `user_roles` ADD CONSTRAINT `user_roles_role_id_roles_id_fk` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE `user_roles` ADD CONSTRAINT `user_roles_role_id_roles_id_fk` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `wishlist_items` ADD CONSTRAINT `wishlist_items_wishlist_id_wishlists_id_fk` FOREIGN KEY (`wishlist_id`) REFERENCES `wishlists`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE `wishlist_items` ADD CONSTRAINT `wishlist_items_wishlist_id_wishlists_id_fk` FOREIGN KEY (`wishlist_id`) REFERENCES `wishlists`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint

View file

@ -1,24 +0,0 @@
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)
);

View file

@ -0,0 +1,2 @@
ALTER TABLE `sessions` ADD `ip_country` varchar(255);--> statement-breakpoint
ALTER TABLE `sessions` ADD `ip_address` varchar(255);

View file

@ -1,7 +1,7 @@
{ {
"version": "5", "version": "5",
"dialect": "mysql", "dialect": "mysql",
"id": "4a97ddeb-b977-401f-ad10-a4ae738d1254", "id": "d90c2144-2349-4a3f-b4f3-87b5ab209936",
"prevId": "00000000-0000-0000-0000-000000000000", "prevId": "00000000-0000-0000-0000-000000000000",
"tables": { "tables": {
"artists": { "artists": {
@ -64,6 +64,29 @@
}, },
"uniqueConstraints": {} "uniqueConstraints": {}
}, },
"artists_to_games": {
"name": "artists_to_games",
"columns": {
"artist_id": {
"name": "artist_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"game_id": {
"name": "game_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"categories": { "categories": {
"name": "categories", "name": "categories",
"columns": { "columns": {
@ -124,6 +147,29 @@
}, },
"uniqueConstraints": {} "uniqueConstraints": {}
}, },
"categories_to_games": {
"name": "categories_to_games",
"columns": {
"category_id": {
"name": "category_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"game_id": {
"name": "game_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"collection_items": { "collection_items": {
"name": "collection_items", "name": "collection_items",
"columns": { "columns": {
@ -324,6 +370,29 @@
}, },
"uniqueConstraints": {} "uniqueConstraints": {}
}, },
"designers_to_games": {
"name": "designers_to_games",
"columns": {
"designer_id": {
"name": "designer_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"game_id": {
"name": "game_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"expansions": { "expansions": {
"name": "expansions", "name": "expansions",
"columns": { "columns": {
@ -615,6 +684,29 @@
}, },
"uniqueConstraints": {} "uniqueConstraints": {}
}, },
"mechanics_to_games": {
"name": "mechanics_to_games",
"columns": {
"mechanic_id": {
"name": "mechanic_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"game_id": {
"name": "game_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"publishers": { "publishers": {
"name": "publishers", "name": "publishers",
"columns": { "columns": {
@ -675,6 +767,29 @@
}, },
"uniqueConstraints": {} "uniqueConstraints": {}
}, },
"publishers_to_games": {
"name": "publishers_to_games",
"columns": {
"publisher_id": {
"name": "publisher_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"game_id": {
"name": "game_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"roles": { "roles": {
"name": "roles", "name": "roles",
"columns": { "columns": {
@ -729,20 +844,6 @@
"notNull": true, "notNull": true,
"autoincrement": false "autoincrement": false
}, },
"ip_country": {
"name": "ip_country",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"ip_address": {
"name": "ip_address",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"expires_at": { "expires_at": {
"name": "expires_at", "name": "expires_at",
"type": "datetime", "type": "datetime",
@ -763,7 +864,7 @@
"columnsTo": [ "columnsTo": [
"id" "id"
], ],
"onDelete": "cascade", "onDelete": "no action",
"onUpdate": "no action" "onUpdate": "no action"
} }
}, },

View file

@ -1,8 +1,8 @@
{ {
"version": "5", "version": "5",
"dialect": "mysql", "dialect": "mysql",
"id": "ab7f5925-a7ee-4cc4-8def-045d0cb29d75", "id": "ede125d1-2fb9-4212-9c56-eeabe6af2332",
"prevId": "4a97ddeb-b977-401f-ad10-a4ae738d1254", "prevId": "d90c2144-2349-4a3f-b4f3-87b5ab209936",
"tables": { "tables": {
"artists": { "artists": {
"name": "artists", "name": "artists",
@ -844,6 +844,13 @@
"notNull": true, "notNull": true,
"autoincrement": false "autoincrement": false
}, },
"expires_at": {
"name": "expires_at",
"type": "datetime",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"ip_country": { "ip_country": {
"name": "ip_country", "name": "ip_country",
"type": "varchar(255)", "type": "varchar(255)",
@ -857,13 +864,6 @@
"primaryKey": false, "primaryKey": false,
"notNull": false, "notNull": false,
"autoincrement": false "autoincrement": false
},
"expires_at": {
"name": "expires_at",
"type": "datetime",
"primaryKey": false,
"notNull": true,
"autoincrement": false
} }
}, },
"indexes": {}, "indexes": {},
@ -878,7 +878,7 @@
"columnsTo": [ "columnsTo": [
"id" "id"
], ],
"onDelete": "cascade", "onDelete": "no action",
"onUpdate": "no action" "onUpdate": "no action"
} }
}, },

View file

@ -1,19 +1,19 @@
{ {
"version": "5", "version": "5",
"dialect": "pg", "dialect": "mysql",
"entries": [ "entries": [
{ {
"idx": 0, "idx": 0,
"version": "5", "version": "5",
"when": 1707012854588, "when": 1707197486310,
"tag": "0000_smooth_thunderbolt", "tag": "0000_true_sugar_man",
"breakpoints": true "breakpoints": true
}, },
{ {
"idx": 1, "idx": 1,
"version": "5", "version": "5",
"when": 1707097761920, "when": 1707199636963,
"tag": "0001_dapper_spiral", "tag": "0001_motionless_old_lace",
"breakpoints": true "breakpoints": true
} }
] ]

View file

@ -18,7 +18,7 @@
"site:update": "pnpm update -i -L", "site:update": "pnpm update -i -L",
"generate": "drizzle-kit generate:mysql", "generate": "drizzle-kit generate:mysql",
"migrate": "tsx ./src/migrate.ts", "migrate": "tsx ./src/migrate.ts",
"db:push": "drizzle-kit push:mysql" "push": "drizzle-kit push:mysql"
}, },
"prisma": { "prisma": {
"seed": "node --loader ts-node/esm prisma/seed.ts" "seed": "node --loader ts-node/esm prisma/seed.ts"
@ -64,6 +64,7 @@
"tailwindcss": "^3.4.1", "tailwindcss": "^3.4.1",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"tslib": "^2.6.1", "tslib": "^2.6.1",
"tsx": "^4.7.0",
"typescript": "^5.3.3", "typescript": "^5.3.3",
"vite": "^5.0.12", "vite": "^5.0.12",
"vitest": "^1.2.2", "vitest": "^1.2.2",

View file

@ -241,6 +241,9 @@ devDependencies:
tslib: tslib:
specifier: ^2.6.1 specifier: ^2.6.1
version: 2.6.2 version: 2.6.2
tsx:
specifier: ^4.7.0
version: 4.7.0
typescript: typescript:
specifier: ^5.3.3 specifier: ^5.3.3
version: 5.3.3 version: 5.3.3
@ -6821,6 +6824,17 @@ packages:
/tslib@2.6.2: /tslib@2.6.2:
resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==}
/tsx@4.7.0:
resolution: {integrity: sha512-I+t79RYPlEYlHn9a+KzwrvEwhJg35h/1zHsLC2JXvhC2mdynMv6Zxzvhv5EMV6VF5qJlLlkSnMVvdZV3PSIGcg==}
engines: {node: '>=18.0.0'}
hasBin: true
dependencies:
esbuild: 0.19.11
get-tsconfig: 4.7.2
optionalDependencies:
fsevents: 2.3.3
dev: true
/type-check@0.4.0: /type-check@0.4.0:
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
engines: {node: '>= 0.8.0'} engines: {node: '>= 0.8.0'}

View file

@ -1,13 +1,18 @@
import { drizzle } from "drizzle-orm/planetscale-serverless"; import { drizzle } from 'drizzle-orm/mysql2';
import { connect } from "@planetscale/database"; import mysql from 'mysql2/promise';
import { DATABASE_USER, DATABASE_PASSWORD, DATABASE_HOST, DATABASE_DB } from '$env/static/private';
console.log('DATABASE_URL', process.env.DATABASE_URL);
// create the connection // create the connection
const connection = connect({ const connection = await mysql.createConnection({
host: process.env["DATABASE_HOST"], user: DATABASE_USER,
username: process.env["DATABASE_USERNAME"], password: DATABASE_PASSWORD,
password: process.env["DATABASE_PASSWORD"], host: DATABASE_HOST,
port: 3306,
database: DATABASE_DB
}); });
const db = drizzle(connection); const db = drizzle(connection);
export default db; export default db;

View file

@ -1,6 +1,8 @@
import prisma from '$lib/prisma.js'; // import prisma from '$lib/prisma.js';
import type { Game } from '@prisma/client'; import db from '$lib/drizzle.js';
import { error, json } from '@sveltejs/kit'; import { error, json } from '@sveltejs/kit';
import { asc, inArray, sql } from 'drizzle-orm';
import { games, type Games } from '../../../../schema.js';
export const GET = async ({ url, locals }) => { export const GET = async ({ url, locals }) => {
const searchParams = Object.fromEntries(url.searchParams); const searchParams = Object.fromEntries(url.searchParams);
@ -10,22 +12,37 @@ export const GET = async ({ url, locals }) => {
error(400, { message: 'Limit must be between 1 and 6' }); error(400, { message: 'Limit must be between 1 and 6' });
} }
const totalGames = await prisma.game.count(); // const totalGames = await prisma.game.count();
const randomIndex = Math.floor(Math.random() * totalGames); try {
const ids: { id: string }[] = await prisma.$queryRaw` console.log('db', db);
SELECT id const dbGames = await db.select({
FROM games count: sql<number>`cast(count(*) as int))`,
ORDER BY id }).from(games);
LIMIT ${limit} console.log('count', dbGames[0].count);
OFFSET ${randomIndex} const randomIndex = Math.floor(Math.random() * dbGames[0]?.count);
`; const ids = await db.select({ id: games.id })
const randomGames: Game[] = await prisma.game.findMany({ .from(games)
where: { .orderBy(asc(games.id))
id: { .limit(limit)
in: ids.map(id => id.id) .offset(randomIndex);
} // const ids: { id: string }[] = await prisma.$queryRaw`
} // SELECT id
}); // FROM games
// ORDER BY id
return json(randomGames); // LIMIT ${limit}
// OFFSET ${randomIndex}
// `;
const randomGames: Games[] = await db.select().from(games).where(inArray(games.id, ids));
return json(randomGames);
} catch (e) {
console.error(e);
throw error(500, { message: 'Something went wrong' });
}
// const randomGames: Game[] = await prisma.game.findMany({
// where: {
// id: {
// in: ids.map(id => id.id)
// }
// }
// });
} }

View file

@ -1,28 +1,7 @@
import { relations, sql } from 'drizzle-orm'; import { relations, sql, type InferSelectModel } from 'drizzle-orm';
import { mysqlTable, datetime, varchar, boolean, timestamp, year, int, text } from 'drizzle-orm/mysql-core'; import { mysqlTable, datetime, varchar, boolean, year, int, text } from 'drizzle-orm/mysql-core';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
// model User {
// id String @id @default(cuid())
// username String @unique
// hashed_password String?
// email String? @unique
// firstName String?
// lastName String?
// roles UserRole[]
// verified Boolean @default(false)
// receiveEmail Boolean @default(false)
// collection Collection?
// wishlist Wishlist?
// list List[]
// theme String @default("system")
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// sessions Session[]
// @@map("users")
// }
export const users = mysqlTable("users", { export const users = mysqlTable("users", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -56,45 +35,26 @@ export const user_relations = relations(users, ({ many }) => ({
user_roles: many(user_roles) user_roles: many(user_roles)
})); }));
// model Session { export type Users = InferSelectModel<typeof users>;
// id String @id @unique
// userId String
// ip_country String
// ip_address String
// expiresAt DateTime
// user User @relation(references: [id], fields: [userId], onDelete: Cascade)
// @@index([userId]) export const sessions = mysqlTable('sessions', {
// @@map("sessions") id: varchar('id', {
// }
export const sessions = mysqlTable("sessions", {
id: varchar("id", {
length: 255 length: 255
}).primaryKey() }).primaryKey(),
.$defaultFn(() => nanoid()), userId: varchar('user_id', {
userId: varchar("user_id", {
length: 255 length: 255
}) })
.notNull() .notNull()
.references(() => users.id, { onDelete: 'cascade' }), .references(() => users.id),
ipCountry: varchar("ip_country", { expiresAt: datetime('expires_at').notNull(),
ipCountry: varchar('ip_country', {
length: 255 length: 255
}), }),
ipAddress: varchar("ip_address", { ipAddress: varchar('ip_address', {
length: 255 length: 255
}), })
expiresAt: datetime("expires_at").notNull()
}); });
// model Role {
// id String @id @default(cuid())
// name String @unique
// userRoles UserRole[]
// @@map("roles")
// }
export const roles = mysqlTable("roles", { export const roles = mysqlTable("roles", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -105,21 +65,6 @@ export const roles = mysqlTable("roles", {
}).unique() }).unique()
}); });
// model UserRole {
// id String @id @default(cuid())
// user User @relation(fields: [user_id], references: [id])
// user_id String
// role Role @relation(fields: [role_id], references: [id])
// role_id String
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@unique([user_id, role_id])
// @@index([user_id])
// @@index([role_id])
// @@map("user_roles")
// }
export const user_roles = mysqlTable("user_roles", { export const user_roles = mysqlTable("user_roles", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -150,43 +95,6 @@ export const user_role_relations = relations(user_roles, ({ one }) => ({
}) })
})); }));
// model Game {
// id String @id @default(cuid())
// name String
// slug String
// description String? @db.LongText
// year_published Int? @db.Year
// min_players Int?
// max_players Int?
// playtime Int?
// min_playtime Int?
// max_playtime Int?
// min_age Int?
// image_url String?
// thumb_url String?
// url String?
// rules_url String?
// categories Category[]
// mechanics Mechanic[]
// designers Designer[]
// publishers Publisher[]
// artists Artist[]
// names GameName[]
// expansions Expansion[] @relation("BaseToExpansion")
// expansion_of Expansion[] @relation("ExpansionToBase")
// collection_items CollectionItem[]
// wishlist_items WishlistItem[]
// list_items ListItem[]
// external_id Int @unique
// last_sync_at DateTime? @db.Timestamp(6)
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@fulltext([slug])
// @@map("games")
// }
export const games = mysqlTable("games", { export const games = mysqlTable("games", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -221,6 +129,8 @@ export const games = mysqlTable("games", {
updatedAt: datetime("updated_at").default(sql`(now(6))`) updatedAt: datetime("updated_at").default(sql`(now(6))`)
}); });
export type Games = InferSelectModel<typeof games>;
export const gameRelations = relations(games, ({ many }) => ({ export const gameRelations = relations(games, ({ many }) => ({
categories_to_games: many(categories_to_games), categories_to_games: many(categories_to_games),
mechanics_to_games: many(mechanics_to_games), mechanics_to_games: many(mechanics_to_games),
@ -229,20 +139,6 @@ export const gameRelations = relations(games, ({ many }) => ({
artists_to_games: many(artists_to_games), artists_to_games: many(artists_to_games),
})) }))
// model Expansion {
// id String @id @default(cuid())
// base_game Game @relation(name: "BaseToExpansion", fields: [base_game_id], references: [id])
// base_game_id String
// game Game @relation(name: "ExpansionToBase", fields: [game_id], references: [id])
// game_id String
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@index([base_game_id])
// @@index([game_id])
// @@map("expansions")
// }
export const expansions = mysqlTable("expansions", { export const expansions = mysqlTable("expansions", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -273,16 +169,6 @@ export const expansion_relations = relations(expansions, ({ one }) => ({
}) })
})); }));
// model Collection {
// id String @id @default(cuid())
// user_id String @unique
// user User @relation(references: [id], fields: [user_id])
// items CollectionItem[]
// @@index([user_id])
// @@map("collections")
// }
export const collections = mysqlTable("collections", { export const collections = mysqlTable("collections", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -304,20 +190,6 @@ export const collection_relations = relations(collections, ({ one }) => ({
}), }),
})) }))
// model CollectionItem {
// id String @id @default(cuid())
// collection_id String
// collection Collection @relation(references: [id], fields: [collection_id], onDelete: Cascade)
// game_id String @unique
// game Game @relation(references: [id], fields: [game_id])
// times_played Int
// @@index([game_id, collection_id])
// @@index([game_id])
// @@index([collection_id])
// @@map("collection_items")
// }
export const collection_items = mysqlTable("collection_items", { export const collection_items = mysqlTable("collection_items", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -348,16 +220,6 @@ export const collection_item_relations = relations(collection_items, ({ one }) =
}) })
})); }));
// model Wishlist {
// id String @id @default(cuid())
// user_id String @unique
// user User @relation(references: [id], fields: [user_id])
// items WishlistItem[]
// @@index([user_id])
// @@map("wishlists")
// }
export const wishlists = mysqlTable("wishlists", { export const wishlists = mysqlTable("wishlists", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -379,21 +241,6 @@ export const wishlists_relations = relations(wishlists, ({ one }) => ({
}), }),
})) }))
// model WishlistItem {
// id String @id @default(cuid())
// wishlist_id String
// wishlist Wishlist @relation(references: [id], fields: [wishlist_id], onDelete: Cascade)
// game_id String @unique
// game Game @relation(references: [id], fields: [game_id])
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@index([game_id, wishlist_id])
// @@index([game_id])
// @@index([wishlist_id])
// @@map("wishlist_items")
// }
export const wishlist_items = mysqlTable('wishlist_items', { export const wishlist_items = mysqlTable('wishlist_items', {
id: varchar('id', { id: varchar('id', {
length: 255 length: 255
@ -425,58 +272,6 @@ export const wishlist_item_relations = relations(wishlist_items, ({ one }) => ({
}) })
})) }))
// model List {
// id String @id @default(cuid())
// name String
// user_id String @unique
// user User @relation(references: [id], fields: [user_id])
// items ListItem[]
// @@index([user_id])
// @@map("lists")
// }
// model ListItem {
// id String @id @default(cuid())
// list_id String
// list List @relation(references: [id], fields: [list_id], onDelete: Cascade)
// game_id String @unique
// game Game @relation(references: [id], fields: [game_id])
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@index([game_id, list_id])
// @@index([game_id])
// @@index([list_id])
// @@map("list_items")
// }
// model GameName {
// id String @id @default(cuid())
// name String
// slug String
// game_id String
// game Game @relation(references: [id], fields: [game_id])
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@index([game_id])
// @@map("game_names")
// }
// model Publisher {
// id String @id @default(cuid())
// name String
// slug String
// external_id Int @unique
// games Game[]
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@map("publishers")
// }
export const publishers = mysqlTable("publishers", { export const publishers = mysqlTable("publishers", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -497,19 +292,6 @@ export const publishers_relations = relations(publishers, ({ many }) => ({
publishers_to_games: many(publishers_to_games) publishers_to_games: many(publishers_to_games)
})); }));
// model Category {
// id String @id @default(cuid())
// name String
// slug String
// games Game[]
// external_id Int @unique
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@map("categories")
// }
export const categories = mysqlTable("categories", { export const categories = mysqlTable("categories", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -530,19 +312,6 @@ export const categories_relations = relations(categories, ({ many }) => ({
categories_to_games: many(categories_to_games) categories_to_games: many(categories_to_games)
})); }));
// model Mechanic {
// id String @id @default(cuid())
// name String
// slug String
// games Game[]
// external_id Int @unique
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@map("mechanics")
// }
export const mechanics = mysqlTable("mechanics", { export const mechanics = mysqlTable("mechanics", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -563,19 +332,6 @@ export const mechanic_relations = relations(mechanics, ({ many }) => ({
mechanics_to_games: many(mechanics_to_games) mechanics_to_games: many(mechanics_to_games)
})) }))
// model Designer {
// id String @id @default(cuid())
// name String
// slug String
// external_id Int @unique
// games Game[]
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@map("designers")
// }
export const designers = mysqlTable("designers", { export const designers = mysqlTable("designers", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
@ -596,19 +352,6 @@ export const designers_relations = relations(designers, ({ many }) => ({
designers_to_games: many(designers_to_games) designers_to_games: many(designers_to_games)
})); }));
// model Artist {
// id String @id @default(cuid())
// name String
// slug String @unique
// external_id Int @unique
// games Game[]
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@map("artists")
// }
export const artists = mysqlTable("artists", { export const artists = mysqlTable("artists", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255