From 30cd8ceb97028af9ae0b35df4b84a747eb4afb8f Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Sat, 3 Feb 2024 18:21:32 -0800 Subject: [PATCH] Updating schema for drizzle, adding migrate and push. --- drizzle.config.ts | 2 +- drizzle/0000_smooth_thunderbolt.sql | 169 ++++ drizzle/meta/0000_snapshot.json | 1118 +++++++++++++++++++++++++++ drizzle/meta/_journal.json | 13 + package.json | 9 +- pnpm-lock.yaml | 8 + src/lib/server/auth.ts | 4 +- src/migrate.ts | 12 + src/schema.ts | 670 ++++++++++------ 9 files changed, 1777 insertions(+), 228 deletions(-) create mode 100644 drizzle/0000_smooth_thunderbolt.sql create mode 100644 drizzle/meta/0000_snapshot.json create mode 100644 drizzle/meta/_journal.json create mode 100644 src/migrate.ts diff --git a/drizzle.config.ts b/drizzle.config.ts index cda1800..e06904c 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -6,6 +6,6 @@ export default defineConfig({ out: './drizzle', driver: 'mysql2', dbCredentials: { - connectionString: process.env.DATABASE_URL + uri: `${process.env.DATABASE_URL}` } }); \ No newline at end of file diff --git a/drizzle/0000_smooth_thunderbolt.sql b/drizzle/0000_smooth_thunderbolt.sql new file mode 100644 index 0000000..d8fa1f7 --- /dev/null +++ b/drizzle/0000_smooth_thunderbolt.sql @@ -0,0 +1,169 @@ +CREATE TABLE `artists` ( + `id` varchar(255) NOT NULL, + `name` varchar(255), + `slug` varchar(255), + `external_id` int, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `artists_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `categories` ( + `id` varchar(255) NOT NULL, + `name` varchar(255), + `slug` varchar(255), + `external_id` int, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `categories_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `collection_items` ( + `id` varchar(255) NOT NULL, + `collection_id` varchar(255) NOT NULL, + `game_id` varchar(255) NOT NULL, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `collection_items_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `collections` ( + `id` varchar(255) NOT NULL, + `user_id` varchar(255) NOT NULL, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `collections_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `designers` ( + `id` varchar(255) NOT NULL, + `name` varchar(255), + `slug` varchar(255), + `external_id` int, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `designers_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `expansions` ( + `id` varchar(255) NOT NULL, + `base_game_id` varchar(255) NOT NULL, + `game_id` varchar(255) NOT NULL, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `expansions_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `games` ( + `id` varchar(255) NOT NULL, + `name` varchar(255), + `slug` varchar(255), + `description` text, + `year_published` year, + `min_players` int, + `max_players` int, + `playtime` int, + `min_playtime` int, + `max_playtime` int, + `min_age` int, + `image_url` varchar(255), + `thumb_url` varchar(255), + `url` varchar(255), + `external_id` int, + `last_sync_at` datetime, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `games_id` PRIMARY KEY(`id`), + CONSTRAINT `games_external_id_unique` UNIQUE(`external_id`) +); +--> statement-breakpoint +CREATE TABLE `mechanics` ( + `id` varchar(255) NOT NULL, + `name` varchar(255), + `slug` varchar(255), + `external_id` int, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `mechanics_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `publishers` ( + `id` varchar(255) NOT NULL, + `name` varchar(255), + `slug` varchar(255), + `external_id` int, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `publishers_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `roles` ( + `id` varchar(255) NOT NULL, + `name` varchar(255), + CONSTRAINT `roles_id` PRIMARY KEY(`id`), + CONSTRAINT `roles_name_unique` UNIQUE(`name`) +); +--> statement-breakpoint +CREATE TABLE `sessions` ( + `id` varchar(255) NOT NULL, + `user_id` varchar(255) NOT NULL, + `ip_country` varchar(255), + `ip_address` varchar(255), + `expires_at` datetime NOT NULL, + CONSTRAINT `sessions_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `user_roles` ( + `id` varchar(255) NOT NULL, + `user_id` varchar(255) NOT NULL, + `role_id` varchar(255) NOT NULL, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `user_roles_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `users` ( + `id` varchar(255) NOT NULL, + `username` varchar(255), + `hashed_password` varchar(255), + `email` varchar(255), + `first_name` varchar(255), + `last_name` varchar(255), + `verified` boolean DEFAULT false, + `receive_email` boolean DEFAULT false, + `theme` varchar(255) DEFAULT 'system', + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `users_id` PRIMARY KEY(`id`), + CONSTRAINT `users_username_unique` UNIQUE(`username`), + CONSTRAINT `users_email_unique` UNIQUE(`email`) +); +--> statement-breakpoint +CREATE TABLE `wishlist_items` ( + `id` varchar(255) NOT NULL, + `wishlist_id` varchar(255) NOT NULL, + `game_id` varchar(255) NOT NULL, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `wishlist_items_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `wishlists` ( + `id` varchar(255) NOT NULL, + `user_id` varchar(255) NOT NULL, + `created_at` datetime DEFAULT (now(6)), + `updated_at` datetime DEFAULT (now(6)), + CONSTRAINT `wishlists_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +ALTER TABLE `collection_items` ADD CONSTRAINT `collection_items_collection_id_collections_id_fk` FOREIGN KEY (`collection_id`) REFERENCES `collections`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `collection_items` ADD CONSTRAINT `collection_items_game_id_games_id_fk` FOREIGN KEY (`game_id`) REFERENCES `games`(`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_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 `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 `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_game_id_games_id_fk` FOREIGN KEY (`game_id`) REFERENCES `games`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `wishlists` ADD CONSTRAINT `wishlists_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action; \ No newline at end of file diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json new file mode 100644 index 0000000..40431d3 --- /dev/null +++ b/drizzle/meta/0000_snapshot.json @@ -0,0 +1,1118 @@ +{ + "version": "5", + "dialect": "mysql", + "id": "4a97ddeb-b977-401f-ad10-a4ae738d1254", + "prevId": "00000000-0000-0000-0000-000000000000", + "tables": { + "artists": { + "name": "artists", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "artists_id": { + "name": "artists_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "categories": { + "name": "categories", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "categories_id": { + "name": "categories_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "collection_items": { + "name": "collection_items", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "collection_id": { + "name": "collection_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": { + "collection_items_collection_id_collections_id_fk": { + "name": "collection_items_collection_id_collections_id_fk", + "tableFrom": "collection_items", + "tableTo": "collections", + "columnsFrom": [ + "collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "collection_items_game_id_games_id_fk": { + "name": "collection_items_game_id_games_id_fk", + "tableFrom": "collection_items", + "tableTo": "games", + "columnsFrom": [ + "game_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "collection_items_id": { + "name": "collection_items_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "collections": { + "name": "collections", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": { + "collections_user_id_users_id_fk": { + "name": "collections_user_id_users_id_fk", + "tableFrom": "collections", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "collections_id": { + "name": "collections_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "designers": { + "name": "designers", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "designers_id": { + "name": "designers_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "expansions": { + "name": "expansions", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base_game_id": { + "name": "base_game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": { + "expansions_base_game_id_games_id_fk": { + "name": "expansions_base_game_id_games_id_fk", + "tableFrom": "expansions", + "tableTo": "games", + "columnsFrom": [ + "base_game_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "expansions_game_id_games_id_fk": { + "name": "expansions_game_id_games_id_fk", + "tableFrom": "expansions", + "tableTo": "games", + "columnsFrom": [ + "game_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "expansions_id": { + "name": "expansions_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "games": { + "name": "games", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "year_published": { + "name": "year_published", + "type": "year", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "min_players": { + "name": "min_players", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "max_players": { + "name": "max_players", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "playtime": { + "name": "playtime", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "min_playtime": { + "name": "min_playtime", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "max_playtime": { + "name": "max_playtime", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "min_age": { + "name": "min_age", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image_url": { + "name": "image_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "thumb_url": { + "name": "thumb_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "games_id": { + "name": "games_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": { + "games_external_id_unique": { + "name": "games_external_id_unique", + "columns": [ + "external_id" + ] + } + } + }, + "mechanics": { + "name": "mechanics", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "mechanics_id": { + "name": "mechanics_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "publishers": { + "name": "publishers", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "publishers_id": { + "name": "publishers_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "roles": { + "name": "roles", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "roles_id": { + "name": "roles_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": { + "roles_name_unique": { + "name": "roles_name_unique", + "columns": [ + "name" + ] + } + } + }, + "sessions": { + "name": "sessions", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "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": { + "name": "expires_at", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "sessions_id": { + "name": "sessions_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "user_roles": { + "name": "user_roles", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role_id": { + "name": "role_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": { + "user_roles_user_id_users_id_fk": { + "name": "user_roles_user_id_users_id_fk", + "tableFrom": "user_roles", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_role_id_roles_id_fk": { + "name": "user_roles_role_id_roles_id_fk", + "tableFrom": "user_roles", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "user_roles_id": { + "name": "user_roles_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "username": { + "name": "username", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hashed_password": { + "name": "hashed_password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "first_name": { + "name": "first_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_name": { + "name": "last_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "receive_email": { + "name": "receive_email", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "theme": { + "name": "theme", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'system'" + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "users_id": { + "name": "users_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": { + "users_username_unique": { + "name": "users_username_unique", + "columns": [ + "username" + ] + }, + "users_email_unique": { + "name": "users_email_unique", + "columns": [ + "email" + ] + } + } + }, + "wishlist_items": { + "name": "wishlist_items", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "wishlist_id": { + "name": "wishlist_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": { + "wishlist_items_wishlist_id_wishlists_id_fk": { + "name": "wishlist_items_wishlist_id_wishlists_id_fk", + "tableFrom": "wishlist_items", + "tableTo": "wishlists", + "columnsFrom": [ + "wishlist_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "wishlist_items_game_id_games_id_fk": { + "name": "wishlist_items_game_id_games_id_fk", + "tableFrom": "wishlist_items", + "tableTo": "games", + "columnsFrom": [ + "game_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "wishlist_items_id": { + "name": "wishlist_items_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + }, + "wishlists": { + "name": "wishlists", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + }, + "updated_at": { + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(now(6))" + } + }, + "indexes": {}, + "foreignKeys": { + "wishlists_user_id_users_id_fk": { + "name": "wishlists_user_id_users_id_fk", + "tableFrom": "wishlists", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "wishlists_id": { + "name": "wishlists_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {} + } + }, + "schemas": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json new file mode 100644 index 0000000..027688f --- /dev/null +++ b/drizzle/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "5", + "dialect": "pg", + "entries": [ + { + "idx": 0, + "version": "5", + "when": 1707012854588, + "tag": "0000_smooth_thunderbolt", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index eb85754..b5d132e 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,9 @@ "lint": "prettier --plugin-search-dir . --check . && eslint .", "format": "prettier --plugin-search-dir . --write .", "site:update": "pnpm update -i -L", - "db:studio": "prisma studio", - "db:push": "prisma db push", - "db:generate": "prisma generate", - "db:seed": "prisma db seed", - "i-changed-the-schema": "pnpm run db:push && pnpm run db:generate" + "generate": "drizzle-kit generate:mysql", + "migrate": "tsx ./src/migrate.ts", + "db:push": "drizzle-kit push:mysql" }, "prisma": { "seed": "node --loader ts-node/esm prisma/seed.ts" @@ -39,6 +37,7 @@ "@typescript-eslint/eslint-plugin": "^6.20.0", "@typescript-eslint/parser": "^6.20.0", "autoprefixer": "^10.4.17", + "dotenv": "^16.4.1", "drizzle-kit": "^0.20.13", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fd92865..e759db2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -160,6 +160,9 @@ devDependencies: autoprefixer: specifier: ^10.4.17 version: 10.4.17(postcss@8.4.33) + dotenv: + specifier: ^16.4.1 + version: 16.4.1 drizzle-kit: specifier: ^0.20.13 version: 0.20.13 @@ -3863,6 +3866,11 @@ packages: esutils: 2.0.3 dev: true + /dotenv@16.4.1: + resolution: {integrity: sha512-CjA3y+Dr3FyFDOAMnxZEGtnW9KBR2M0JvvUtXNW+dYJL5ROWxP9DUHCwgFqpMk0OXCc0ljhaNTr2w/kutYIcHQ==} + engines: {node: '>=12'} + dev: true + /dreamopt@0.8.0: resolution: {integrity: sha512-vyJTp8+mC+G+5dfgsY+r3ckxlz+QMX40VjPQsZc5gxVAxLmi64TBoVkP54A/pRAXMXsbu2GMMBrZPxNv23waMg==} engines: {node: '>=0.4.0'} diff --git a/src/lib/server/auth.ts b/src/lib/server/auth.ts index 21f848b..3f35e08 100644 --- a/src/lib/server/auth.ts +++ b/src/lib/server/auth.ts @@ -3,9 +3,9 @@ import { Lucia, TimeSpan } from 'lucia'; import { DrizzleMySQLAdapter } from "@lucia-auth/adapter-drizzle"; import { dev } from '$app/environment'; import db from '$lib/drizzle'; -import { sessionTable, userTable } from '../../schema'; +import { sessions, users } from '../../schema'; -const adapter = new DrizzleMySQLAdapter(db, sessionTable, userTable); +const adapter = new DrizzleMySQLAdapter(db, sessions, users); export const lucia = new Lucia(adapter, { getSessionAttributes: (attributes) => { diff --git a/src/migrate.ts b/src/migrate.ts new file mode 100644 index 0000000..69d656b --- /dev/null +++ b/src/migrate.ts @@ -0,0 +1,12 @@ +import { drizzle } from "drizzle-orm/mysql2"; +import { migrate } from "drizzle-orm/mysql2/migrator"; +import { createConnection } from "mysql2"; + +const connection = createConnection({ + uri: process.env.DATABASE_URL +}) +const db = drizzle(connection); + +await migrate(db, { migrationsFolder: "drizzle" }); + +await connection.end(); \ No newline at end of file diff --git a/src/schema.ts b/src/schema.ts index f10bfb8..a566559 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1,29 +1,29 @@ import { sql } from 'drizzle-orm'; -import { mysqlTable, datetime, varchar, boolean, timestamp } from 'drizzle-orm/mysql-core'; +import { mysqlTable, datetime, varchar, boolean, timestamp, year, int, text } from 'drizzle-orm/mysql-core'; 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[] +// 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") -} +// @@map("users") +// } -export const userTable = mysqlTable("users", { +export const users = mysqlTable("users", { id: varchar("id", { length: 255 }).primaryKey() @@ -48,10 +48,12 @@ export const userTable = mysqlTable("users", { theme: varchar("theme", { length: 255 }).default("system"), - createdAt: timestamp("created_at").default(sql`(now(6))`), - updatedAt: timestamp("updated_at").default(sql`(now(6))`) + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) }); + + // model Session { // id String @id @unique // userId String @@ -64,7 +66,7 @@ export const userTable = mysqlTable("users", { // @@map("sessions") // } -export const sessionTable = mysqlTable("sessions", { +export const sessions = mysqlTable("sessions", { id: varchar("id", { length: 255 }).primaryKey() @@ -73,7 +75,7 @@ export const sessionTable = mysqlTable("sessions", { length: 255 }) .notNull() - .references(() => userTable.id), + .references(() => users.id, { onDelete: 'cascade' }), ipCountry: varchar("ip_country", { length: 255 }), @@ -83,229 +85,457 @@ export const sessionTable = mysqlTable("sessions", { expiresAt: datetime("expires_at").notNull() }); -model Role { - id String @id @default(cuid()) - name String @unique - userRoles UserRole[] +// model Role { +// id String @id @default(cuid()) +// name String @unique +// userRoles UserRole[] - @@map("roles") -} +// @@map("roles") +// } -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) +export const roles = mysqlTable("roles", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + name: varchar("name", { + length: 255 + }).unique() +}); - @@unique([user_id, role_id]) - @@index([user_id]) - @@index([role_id]) - @@map("user_roles") -} +// 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) -model Collection { - id String @id @default(cuid()) - user_id String @unique - user User @relation(references: [id], fields: [user_id]) - items CollectionItem[] +// @@unique([user_id, role_id]) +// @@index([user_id]) +// @@index([role_id]) +// @@map("user_roles") +// } - @@index([user_id]) - @@map("collections") -} +export const userRoles = mysqlTable("user_roles", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + userId: varchar("user_id", { + length: 255 + }) + .notNull() + .references(() => users.id, { onDelete: 'cascade' }), + roleId: varchar("role_id", { + length: 255 + }) + .notNull() + .references(() => roles.id, { onDelete: 'cascade' }), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}); -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 +// 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) - @@index([game_id, collection_id]) - @@index([game_id]) - @@index([collection_id]) - @@map("collection_items") -} +// @@fulltext([name]) +// @@fulltext([slug]) +// @@map("games") +// } -model Wishlist { - id String @id @default(cuid()) - user_id String @unique - user User @relation(references: [id], fields: [user_id]) - items WishlistItem[] +export const games = mysqlTable("games", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + name: varchar("name", { + length: 255 + }), + slug: varchar("slug", { + length: 255 + }), + description: text("description"), + yearPublished: year("year_published"), + minPlayers: int("min_players"), + maxPlayers: int("max_players"), + playtime: int("playtime"), + minPlaytime: int("min_playtime"), + maxPlaytime: int("max_playtime"), + minAge: int("min_age"), + imageUrl: varchar("image_url", { + length: 255 + }), + thumbUrl: varchar("thumb_url", { + length: 255 + }), + url: varchar("url", { + length: 255 + }), + externalId: int("external_id").unique(), + lastSyncAt: datetime("last_sync_at"), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}) - @@index([user_id]) - @@map("wishlists") -} +// 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) -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([base_game_id]) +// @@index([game_id]) +// @@map("expansions") +// } - @@index([game_id, wishlist_id]) - @@index([game_id]) - @@index([wishlist_id]) - @@map("wishlist_items") -} +export const expansions = mysqlTable("expansions", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + baseGameId: varchar("base_game_id", { + length: 255 + }) + .notNull() + .references(() => games.id, { onDelete: 'cascade' }), + gameId: varchar("game_id", { + length: 255 + }) + .notNull() + .references(() => games.id, { onDelete: 'cascade' }), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}) -model List { - id String @id @default(cuid()) - name String - user_id String @unique - user User @relation(references: [id], fields: [user_id]) - items ListItem[] +// 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("lists") -} +// @@index([user_id]) +// @@map("collections") +// } -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) +export const collections = mysqlTable("collections", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + userId: varchar("user_id", { + length: 255 + }) + .notNull() + .references(() => users.id, { onDelete: 'cascade' }), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}) - @@index([game_id, list_id]) - @@index([game_id]) - @@index([list_id]) - @@map("list_items") -} +// 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 -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) +// @@index([game_id, collection_id]) +// @@index([game_id]) +// @@index([collection_id]) +// @@map("collection_items") +// } - @@fulltext([name]) - @@fulltext([slug]) - @@map("games") -} +export const collectionItems = mysqlTable("collection_items", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + collectionId: varchar("collection_id", { + length: 255 + }) + .notNull() + .references(() => collections.id, { onDelete: 'cascade' }), + gameId: varchar("game_id", { + length: 255 + }) + .notNull() + .references(() => games.id, { onDelete: 'cascade' }), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}) -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) +// model Wishlist { +// id String @id @default(cuid()) +// user_id String @unique +// user User @relation(references: [id], fields: [user_id]) +// items WishlistItem[] - @@index([game_id]) - @@map("game_names") -} +// @@index([user_id]) +// @@map("wishlists") +// } -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) +export const wishlists = mysqlTable("wishlists", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + userId: varchar("user_id", { + length: 255 + }) + .notNull() + .references(() => users.id, { onDelete: 'cascade' }), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}); - @@fulltext([name]) - @@map("publishers") -} +// 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) -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) +// @@index([game_id, wishlist_id]) +// @@index([game_id]) +// @@index([wishlist_id]) +// @@map("wishlist_items") +// } - @@fulltext([name]) - @@map("categories") -} +export const wishlistItems = mysqlTable("wishlist_items", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + wishlistId: varchar("wishlist_id", { + length: 255 + }) + .notNull() + .references(() => wishlists.id, { onDelete: 'cascade' }), + gameId: varchar("game_id", { + length: 255 + }) + .notNull() + .references(() => games.id, { onDelete: 'cascade' }), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}); -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) +// model List { +// id String @id @default(cuid()) +// name String +// user_id String @unique +// user User @relation(references: [id], fields: [user_id]) +// items ListItem[] - @@fulltext([name]) - @@map("mechanics") -} +// @@index([user_id]) +// @@map("lists") +// } -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) +// 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) - @@fulltext([name]) - @@map("designers") -} +// @@index([game_id, list_id]) +// @@index([game_id]) +// @@index([list_id]) +// @@map("list_items") +// } -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) +// 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) - @@fulltext([name]) - @@map("artists") -} +// @@index([game_id]) +// @@map("game_names") +// } -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) +// 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) - @@index([base_game_id]) - @@index([game_id]) - @@map("expansions") -} \ No newline at end of file +// @@fulltext([name]) +// @@map("publishers") +// } + +export const publishers = mysqlTable("publishers", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + name: varchar("name", { + length: 255 + }), + slug: varchar("slug", { + length: 255 + }), + externalId: int("external_id"), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}) + +// 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", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + name: varchar("name", { + length: 255 + }), + slug: varchar("slug", { + length: 255 + }), + externalId: int("external_id"), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}) + +// 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", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + name: varchar("name", { + length: 255 + }), + slug: varchar("slug", { + length: 255 + }), + externalId: int("external_id"), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}) + +// 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", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + name: varchar("name", { + length: 255 + }), + slug: varchar("slug", { + length: 255 + }), + externalId: int("external_id"), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +}) + +// 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", { + id: varchar("id", { + length: 255 + }).primaryKey() + .$defaultFn(() => nanoid()), + name: varchar("name", { + length: 255 + }), + slug: varchar("slug", { + length: 255 + }), + externalId: int("external_id"), + createdAt: datetime("created_at").default(sql`(now(6))`), + updatedAt: datetime("updated_at").default(sql`(now(6))`) +})