diff --git a/drizzle/0007_same_valeria_richards.sql b/drizzle/0007_same_valeria_richards.sql new file mode 100644 index 0000000..2805de8 --- /dev/null +++ b/drizzle/0007_same_valeria_richards.sql @@ -0,0 +1,71 @@ +CREATE TABLE IF NOT EXISTS "categories_to_external_ids" ( + "category_id" varchar(255) NOT NULL, + "external_id" varchar(255) NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "expansions_to_external_ids" ( + "expansion_id" varchar(255) NOT NULL, + "external_id" varchar(255) NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "mechanics_to_external_ids" ( + "mechanic_id" varchar(255) NOT NULL, + "external_id" varchar(255) NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "publishers_to_external_ids" ( + "publisher_id" varchar(255) NOT NULL, + "external_id" varchar(255) NOT NULL +); +--> statement-breakpoint +DROP TABLE "artists";--> statement-breakpoint +DROP TABLE "artists_to_games";--> statement-breakpoint +DROP TABLE "designers";--> statement-breakpoint +DROP TABLE "designers_to_games";--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "categories_to_external_ids" ADD CONSTRAINT "categories_to_external_ids_category_id_categories_id_fk" FOREIGN KEY ("category_id") REFERENCES "categories"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "categories_to_external_ids" ADD CONSTRAINT "categories_to_external_ids_external_id_external_ids_id_fk" FOREIGN KEY ("external_id") REFERENCES "external_ids"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "expansions_to_external_ids" ADD CONSTRAINT "expansions_to_external_ids_expansion_id_expansions_id_fk" FOREIGN KEY ("expansion_id") REFERENCES "expansions"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "expansions_to_external_ids" ADD CONSTRAINT "expansions_to_external_ids_external_id_external_ids_id_fk" FOREIGN KEY ("external_id") REFERENCES "external_ids"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "mechanics_to_external_ids" ADD CONSTRAINT "mechanics_to_external_ids_mechanic_id_mechanics_id_fk" FOREIGN KEY ("mechanic_id") REFERENCES "mechanics"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "mechanics_to_external_ids" ADD CONSTRAINT "mechanics_to_external_ids_external_id_external_ids_id_fk" FOREIGN KEY ("external_id") REFERENCES "external_ids"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "publishers_to_external_ids" ADD CONSTRAINT "publishers_to_external_ids_publisher_id_publishers_id_fk" FOREIGN KEY ("publisher_id") REFERENCES "publishers"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "publishers_to_external_ids" ADD CONSTRAINT "publishers_to_external_ids_external_id_external_ids_id_fk" FOREIGN KEY ("external_id") REFERENCES "external_ids"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/drizzle/meta/0007_snapshot.json b/drizzle/meta/0007_snapshot.json new file mode 100644 index 0000000..f4c3326 --- /dev/null +++ b/drizzle/meta/0007_snapshot.json @@ -0,0 +1,1194 @@ +{ + "id": "8dc4605d-a330-4ccb-950d-d5f1471d9ab8", + "prevId": "713ce980-a770-4f82-8414-a7bd9923262e", + "version": "5", + "dialect": "pg", + "tables": { + "categories": { + "name": "categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "external_id": { + "name": "external_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "categories_to_external_ids": { + "name": "categories_to_external_ids", + "schema": "", + "columns": { + "category_id": { + "name": "category_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "categories_to_external_ids_category_id_categories_id_fk": { + "name": "categories_to_external_ids_category_id_categories_id_fk", + "tableFrom": "categories_to_external_ids", + "tableTo": "categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "categories_to_external_ids_external_id_external_ids_id_fk": { + "name": "categories_to_external_ids_external_id_external_ids_id_fk", + "tableFrom": "categories_to_external_ids", + "tableTo": "external_ids", + "columnsFrom": [ + "external_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "categories_to_games": { + "name": "categories_to_games", + "schema": "", + "columns": { + "category_id": { + "name": "category_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "collection_items": { + "name": "collection_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "collection_id": { + "name": "collection_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "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": {}, + "uniqueConstraints": {} + }, + "collections": { + "name": "collections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "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": {}, + "uniqueConstraints": {} + }, + "expansions": { + "name": "expansions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "base_game_id": { + "name": "base_game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "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": {}, + "uniqueConstraints": {} + }, + "expansions_to_external_ids": { + "name": "expansions_to_external_ids", + "schema": "", + "columns": { + "expansion_id": { + "name": "expansion_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "expansions_to_external_ids_expansion_id_expansions_id_fk": { + "name": "expansions_to_external_ids_expansion_id_expansions_id_fk", + "tableFrom": "expansions_to_external_ids", + "tableTo": "expansions", + "columnsFrom": [ + "expansion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "expansions_to_external_ids_external_id_external_ids_id_fk": { + "name": "expansions_to_external_ids_external_id_external_ids_id_fk", + "tableFrom": "expansions_to_external_ids", + "tableTo": "external_ids", + "columnsFrom": [ + "external_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "external_ids": { + "name": "external_ids", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "games": { + "name": "games", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "year_published": { + "name": "year_published", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "min_players": { + "name": "min_players", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "max_players": { + "name": "max_players", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "playtime": { + "name": "playtime", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "min_playtime": { + "name": "min_playtime", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "max_playtime": { + "name": "max_playtime", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "min_age": { + "name": "min_age", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "image_url": { + "name": "image_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "thumb_url": { + "name": "thumb_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "url": { + "name": "url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "text_searchable_index": { + "name": "text_searchable_index", + "type": "tsvector", + "primaryKey": false, + "notNull": false + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "text_searchable_idx": { + "name": "text_searchable_idx", + "columns": [ + "text_searchable_index" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "games_to_external_ids": { + "name": "games_to_external_ids", + "schema": "", + "columns": { + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "games_to_external_ids_game_id_games_id_fk": { + "name": "games_to_external_ids_game_id_games_id_fk", + "tableFrom": "games_to_external_ids", + "tableTo": "games", + "columnsFrom": [ + "game_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "games_to_external_ids_external_id_external_ids_id_fk": { + "name": "games_to_external_ids_external_id_external_ids_id_fk", + "tableFrom": "games_to_external_ids", + "tableTo": "external_ids", + "columnsFrom": [ + "external_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "mechanics": { + "name": "mechanics", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "external_id": { + "name": "external_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "mechanics_to_external_ids": { + "name": "mechanics_to_external_ids", + "schema": "", + "columns": { + "mechanic_id": { + "name": "mechanic_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "mechanics_to_external_ids_mechanic_id_mechanics_id_fk": { + "name": "mechanics_to_external_ids_mechanic_id_mechanics_id_fk", + "tableFrom": "mechanics_to_external_ids", + "tableTo": "mechanics", + "columnsFrom": [ + "mechanic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mechanics_to_external_ids_external_id_external_ids_id_fk": { + "name": "mechanics_to_external_ids_external_id_external_ids_id_fk", + "tableFrom": "mechanics_to_external_ids", + "tableTo": "external_ids", + "columnsFrom": [ + "external_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "mechanics_to_games": { + "name": "mechanics_to_games", + "schema": "", + "columns": { + "mechanic_id": { + "name": "mechanic_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "publishers": { + "name": "publishers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "external_id": { + "name": "external_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "publishers_to_external_ids": { + "name": "publishers_to_external_ids", + "schema": "", + "columns": { + "publisher_id": { + "name": "publisher_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "publishers_to_external_ids_publisher_id_publishers_id_fk": { + "name": "publishers_to_external_ids_publisher_id_publishers_id_fk", + "tableFrom": "publishers_to_external_ids", + "tableTo": "publishers", + "columnsFrom": [ + "publisher_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "publishers_to_external_ids_external_id_external_ids_id_fk": { + "name": "publishers_to_external_ids_external_id_external_ids_id_fk", + "tableFrom": "publishers_to_external_ids", + "tableTo": "external_ids", + "columnsFrom": [ + "external_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "publishers_to_games": { + "name": "publishers_to_games", + "schema": "", + "columns": { + "publisher_id": { + "name": "publisher_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "roles": { + "name": "roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "roles_name_unique": { + "name": "roles_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + } + }, + "sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ip_country": { + "name": "ip_country", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "ip_address": { + "name": "ip_address", + "type": "varchar(255)", + "primaryKey": false, + "notNull": 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": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "user_roles": { + "name": "user_roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "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": {}, + "uniqueConstraints": {} + }, + "users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "hashed_password": { + "name": "hashed_password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "first_name": { + "name": "first_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "last_name": { + "name": "last_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "receive_email": { + "name": "receive_email", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "theme": { + "name": "theme", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "default": "'system'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_username_unique": { + "name": "users_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + }, + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + } + }, + "wishlist_items": { + "name": "wishlist_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "wishlist_id": { + "name": "wishlist_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "game_id": { + "name": "game_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "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": {}, + "uniqueConstraints": {} + }, + "wishlists": { + "name": "wishlists", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "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": {}, + "uniqueConstraints": {} + } + }, + "enums": { + "external_id_type": { + "name": "external_id_type", + "values": { + "game": "game", + "category": "category", + "mechanic": "mechanic", + "publisher": "publisher", + "designer": "designer", + "artist": "artist" + } + } + }, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 6ce5715..4ea7e65 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -50,6 +50,13 @@ "when": 1707932522909, "tag": "0006_light_corsair", "breakpoints": true + }, + { + "idx": 7, + "version": "5", + "when": 1707951501716, + "tag": "0007_same_valeria_richards", + "breakpoints": true } ] } \ No newline at end of file diff --git a/package.json b/package.json index 6d168d8..3864974 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "site:update": "pnpm update -i -L", "generate": "drizzle-kit generate:pg", "migrate": "tsx ./src/migrate.ts", - "seed": "tsx ./src/seed/insert.ts", + "seed": "tsx ./src/seed.ts", "push": "drizzle-kit push:pg" }, "prisma": { @@ -35,6 +35,7 @@ "@sveltejs/vite-plugin-svelte": "^3.0.2", "@types/cookie": "^0.6.0", "@types/node": "^20.11.17", + "@types/pg": "^8.11.0", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", "autoprefixer": "^10.4.17", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2885867..bc16dbb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -64,7 +64,7 @@ dependencies: version: 0.6.0 drizzle-orm: specifier: ^0.29.3 - version: 0.29.3(@neondatabase/serverless@0.8.1)(@planetscale/database@1.16.0)(mysql2@3.9.1)(pg@8.11.3)(postgres@3.4.3) + version: 0.29.3(@neondatabase/serverless@0.8.1)(@planetscale/database@1.16.0)(@types/pg@8.11.0)(mysql2@3.9.1)(pg@8.11.3)(postgres@3.4.3) feather-icons: specifier: ^4.29.1 version: 4.29.1 @@ -160,6 +160,9 @@ devDependencies: '@types/node': specifier: ^20.11.17 version: 20.11.17 + '@types/pg': + specifier: ^8.11.0 + version: 8.11.0 '@typescript-eslint/eslint-plugin': specifier: ^6.21.0 version: 6.21.0(@typescript-eslint/parser@6.21.0)(eslint@8.56.0)(typescript@5.3.3) @@ -3071,6 +3074,13 @@ packages: dependencies: undici-types: 5.26.5 + /@types/pg@8.11.0: + resolution: {integrity: sha512-sDAlRiBNthGjNFfvt0k6mtotoVYVQ63pA8R4EMWka7crawSR60waVYR0HAgmPRs/e2YaeJTD/43OoZ3PFw80pw==} + dependencies: + '@types/node': 20.11.17 + pg-protocol: 1.6.0 + pg-types: 4.0.2 + /@types/pg@8.6.6: resolution: {integrity: sha512-O2xNmXebtwVekJDD+02udOncjVcMZQuTEQEMpKJ0ZRf5E7/9JJX3izhKUcUifBkyKpljyUM6BTgy2trmviKlpw==} dependencies: @@ -3989,7 +3999,7 @@ packages: - supports-color dev: true - /drizzle-orm@0.29.3(@neondatabase/serverless@0.8.1)(@planetscale/database@1.16.0)(mysql2@3.9.1)(pg@8.11.3)(postgres@3.4.3): + /drizzle-orm@0.29.3(@neondatabase/serverless@0.8.1)(@planetscale/database@1.16.0)(@types/pg@8.11.0)(mysql2@3.9.1)(pg@8.11.3)(postgres@3.4.3): resolution: {integrity: sha512-uSE027csliGSGYD0pqtM+SAQATMREb3eSM/U8s6r+Y0RFwTKwftnwwSkqx3oS65UBgqDOM0gMTl5UGNpt6lW0A==} peerDependencies: '@aws-sdk/client-rds-data': '>=3' @@ -4062,6 +4072,7 @@ packages: dependencies: '@neondatabase/serverless': 0.8.1 '@planetscale/database': 1.16.0 + '@types/pg': 8.11.0 mysql2: 3.9.1 pg: 8.11.3 postgres: 3.4.3 @@ -5490,6 +5501,9 @@ packages: object-keys: 1.1.1 dev: false + /obuf@1.1.2: + resolution: {integrity: sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==} + /once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} dependencies: @@ -5634,7 +5648,10 @@ packages: /pg-int8@1.0.1: resolution: {integrity: sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==} engines: {node: '>=4.0.0'} - dev: false + + /pg-numeric@1.0.2: + resolution: {integrity: sha512-BM/Thnrw5jm2kKLE5uJkXqqExRUY/toLHda65XgFTBTFYZyopbKjBe29Ii3RbkvlsMoFwD+tHeGaCjjv0gHlyw==} + engines: {node: '>=4'} /pg-pool@3.6.1(pg@8.11.3): resolution: {integrity: sha512-jizsIzhkIitxCGfPRzJn1ZdcosIt3pz9Sh3V01fm1vZnbnCMgmGl5wvGGdNN2EL9Rmb0EcFoCkixH4Pu+sP9Og==} @@ -5646,7 +5663,6 @@ packages: /pg-protocol@1.6.0: resolution: {integrity: sha512-M+PDm637OY5WM307051+bsDia5Xej6d9IR4GwJse1qA1DIhiKlksvrneZOYQq42OM+spubpcNYEo2FcKQrDk+Q==} - dev: false /pg-types@2.2.0: resolution: {integrity: sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==} @@ -5659,6 +5675,18 @@ packages: postgres-interval: 1.2.0 dev: false + /pg-types@4.0.2: + resolution: {integrity: sha512-cRL3JpS3lKMGsKaWndugWQoLOCoP+Cic8oseVcbr0qhPzYD5DWXK+RZ9LY9wxRf7RQia4SCwQlXk0q6FCPrVng==} + engines: {node: '>=10'} + dependencies: + pg-int8: 1.0.1 + pg-numeric: 1.0.2 + postgres-array: 3.0.2 + postgres-bytea: 3.0.0 + postgres-date: 2.1.0 + postgres-interval: 3.0.0 + postgres-range: 1.1.4 + /pg@8.11.3: resolution: {integrity: sha512-+9iuvG8QfaaUrrph+kpF24cXkH1YOOUeArRNYIxq1viYHZagBxrTno7cecY1Fa44tJeZvaoG+Djpkc3JwehN5g==} engines: {node: '>= 8.0.0'} @@ -6184,16 +6212,30 @@ packages: engines: {node: '>=4'} dev: false + /postgres-array@3.0.2: + resolution: {integrity: sha512-6faShkdFugNQCLwucjPcY5ARoW1SlbnrZjmGl0IrrqewpvxvhSLHimCVzqeuULCbG0fQv7Dtk1yDbG3xv7Veog==} + engines: {node: '>=12'} + /postgres-bytea@1.0.0: resolution: {integrity: sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==} engines: {node: '>=0.10.0'} dev: false + /postgres-bytea@3.0.0: + resolution: {integrity: sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==} + engines: {node: '>= 6'} + dependencies: + obuf: 1.1.2 + /postgres-date@1.0.7: resolution: {integrity: sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==} engines: {node: '>=0.10.0'} dev: false + /postgres-date@2.1.0: + resolution: {integrity: sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==} + engines: {node: '>=12'} + /postgres-interval@1.2.0: resolution: {integrity: sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==} engines: {node: '>=0.10.0'} @@ -6201,6 +6243,13 @@ packages: xtend: 4.0.2 dev: false + /postgres-interval@3.0.0: + resolution: {integrity: sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==} + engines: {node: '>=12'} + + /postgres-range@1.1.4: + resolution: {integrity: sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==} + /postgres@3.4.3: resolution: {integrity: sha512-iHJn4+M9vbTdHSdDzNkC0crHq+1CUdFhx+YqCE+SqWxPjm+Zu63jq7yZborOBF64c8pc58O5uMudyL1FQcHacA==} engines: {node: '>=12'} diff --git a/src/lib/assets/bored-game.svg b/src/lib/assets/bored-game.svg new file mode 100644 index 0000000..159ae83 --- /dev/null +++ b/src/lib/assets/bored-game.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/lib/components/Footer.svelte b/src/lib/components/Footer.svelte index 04728ef..2e779a4 100644 --- a/src/lib/components/Footer.svelte +++ b/src/lib/components/Footer.svelte @@ -1,12 +1,9 @@ + + diff --git a/src/routes/(app)/waitlist/+page.svelte b/src/routes/(app)/waitlist/+page.svelte new file mode 100644 index 0000000..b3bd926 --- /dev/null +++ b/src/routes/(app)/waitlist/+page.svelte @@ -0,0 +1 @@ +

Waitlist

\ No newline at end of file diff --git a/src/routes/api/game/random/+server.ts b/src/routes/api/game/random/+server.ts index b06057d..da55a39 100644 --- a/src/routes/api/game/random/+server.ts +++ b/src/routes/api/game/random/+server.ts @@ -1,10 +1,9 @@ -// import prisma from '$lib/prisma.js'; import db from '$lib/drizzle.js'; import { error, json } from '@sveltejs/kit'; -import { asc, count, inArray, sql } from 'drizzle-orm'; +import { asc, count } from 'drizzle-orm'; import { games, type Games } from '../../../../schema.js'; -export const GET = async ({ url, locals }) => { +export const GET = async ({ url }) => { const searchParams = Object.fromEntries(url.searchParams); const limit = parseInt(searchParams?.limit) || 1; diff --git a/src/schema.ts b/src/schema.ts index 41cbfa3..1bf0bf1 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -3,6 +3,8 @@ import { pgTable, timestamp, varchar, boolean, integer, text, index, pgEnum } fr import { nanoid } from 'nanoid'; import { tsvector } from './tsVector'; +// User Related Schemas + export const users = pgTable('users', { id: varchar('id', { length: 255 @@ -71,6 +73,12 @@ export const roles = pgTable('roles', { }).unique() }); +export type Roles = InferSelectModel; + +export const role_relations = relations(roles, ({ many }) => ({ + user_roles: many(user_roles) +})) + export const user_roles = pgTable('user_roles', { id: varchar('id', { length: 255 @@ -110,138 +118,6 @@ export const user_role_relations = relations(user_roles, ({ one }) => ({ }) })); -export const games = pgTable('games', { - id: varchar('id', { - length: 255 - }) - .primaryKey() - .$defaultFn(() => nanoid()), - name: varchar('name', { - length: 255 - }), - slug: varchar('slug', { - length: 255 - }), - description: text('description'), - year_published: integer('year_published'), - min_players: integer('min_players'), - max_players: integer('max_players'), - playtime: integer('playtime'), - min_playtime: integer('min_playtime'), - max_playtime: integer('max_playtime'), - min_age: integer('min_age'), - image_url: varchar('image_url', { - length: 255 - }), - thumb_url: varchar('thumb_url', { - length: 255 - }), - url: varchar('url', { - length: 255 - }), - text_searchable_index: tsvector('text_searchable_index'), - last_sync_at: timestamp('last_sync_at', { - withTimezone: true, - mode: 'date', - precision: 6 - }), - created_at: timestamp('created_at', { - withTimezone: true, - mode: 'date', - precision: 6 - }).default(sql`now()`), - updated_at: timestamp('updated_at', { - withTimezone: true, - mode: 'date', - precision: 6 - }).default(sql`now()`) -}, (table) => { - return { - text_searchable_idx: index("text_searchable_idx").on(table.text_searchable_index).using(sql`'gin'`) - } -}); - -export type Games = InferSelectModel; - -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), - gameExternalIds: many(gameExternalIds), -})); - -export const externalIdType = pgEnum('external_id_type', [ - 'game', 'category', 'mechanic', 'publisher', 'designer', 'artist' -]); - -export const externalIds = pgTable('external_ids', { - id: varchar('id', { - length: 255 - }) - .primaryKey() - .$defaultFn(() => nanoid()), - type: varchar('type', { - length: 255 - }).notNull(), - externalId: varchar('external_id', { - length: 255 - }).notNull() -}); - -export const gamesToExternalIds = pgTable('games_to_external_ids', { - gameId: varchar('game_id', { - length: 255 - }) - .notNull() - .references(() => games.id, { onDelete: 'cascade' }), - externalId: varchar('external_id', { - length: 255 - }) - .notNull() - .references(() => externalIds.id, { onDelete: 'cascade' }), -}); - -export const expansions = pgTable('expansions', { - id: varchar('id', { - length: 255 - }) - .primaryKey() - .$defaultFn(() => nanoid()), - base_game_id: varchar('base_game_id', { - length: 255 - }) - .notNull() - .references(() => games.id, { onDelete: 'cascade' }), - game_id: varchar('game_id', { - length: 255 - }) - .notNull() - .references(() => games.id, { onDelete: 'cascade' }), - created_at: timestamp('created_at', { - withTimezone: true, - mode: 'date', - precision: 6 - }).default(sql`now()`), - updated_at: timestamp('updated_at', { - withTimezone: true, - mode: 'date', - precision: 6 - }).default(sql`now()`) -}); - -export const expansion_relations = relations(expansions, ({ one }) => ({ - baseGame: one(games, { - fields: [expansions.base_game_id], - references: [games.id] - }), - game: one(games, { - fields: [expansions.game_id], - references: [games.id] - }) -})); - export const collections = pgTable('collections', { id: varchar('id', { length: 255 @@ -380,6 +256,152 @@ export const wishlist_item_relations = relations(wishlist_items, ({ one }) => ({ }) })); +// Game and related table schemas + +export const externalIdType = pgEnum('external_id_type', [ + 'game', 'category', 'mechanic', 'publisher', 'designer', 'artist' +]); + +export const externalIds = pgTable('external_ids', { + id: varchar('id', { + length: 255 + }) + .primaryKey() + .$defaultFn(() => nanoid()), + type: varchar('type', { + length: 255 + }).notNull(), + externalId: varchar('external_id', { + length: 255 + }).notNull() +}); + +export const games = pgTable('games', { + id: varchar('id', { + length: 255 + }) + .primaryKey() + .$defaultFn(() => nanoid()), + name: varchar('name', { + length: 255 + }), + slug: varchar('slug', { + length: 255 + }), + description: text('description'), + year_published: integer('year_published'), + min_players: integer('min_players'), + max_players: integer('max_players'), + playtime: integer('playtime'), + min_playtime: integer('min_playtime'), + max_playtime: integer('max_playtime'), + min_age: integer('min_age'), + image_url: varchar('image_url', { + length: 255 + }), + thumb_url: varchar('thumb_url', { + length: 255 + }), + url: varchar('url', { + length: 255 + }), + text_searchable_index: tsvector('text_searchable_index'), + last_sync_at: timestamp('last_sync_at', { + withTimezone: true, + mode: 'date', + precision: 6 + }), + created_at: timestamp('created_at', { + withTimezone: true, + mode: 'date', + precision: 6 + }).default(sql`now()`), + updated_at: timestamp('updated_at', { + withTimezone: true, + mode: 'date', + precision: 6 + }).default(sql`now()`) +}, (table) => { + return { + text_searchable_idx: index("text_searchable_idx").on(table.text_searchable_index).using(sql`'gin'`) + } +}); + +export type Games = InferSelectModel; + +export const gamesToExternalIds = pgTable('games_to_external_ids', { + gameId: varchar('game_id', { + length: 255 + }) + .notNull() + .references(() => games.id, { onDelete: 'cascade' }), + externalId: varchar('external_id', { + length: 255 + }) + .notNull() + .references(() => externalIds.id, { onDelete: 'cascade' }), +}); + +export const gameRelations = relations(games, ({ many }) => ({ + categories_to_games: many(categories_to_games), + mechanics_to_games: many(mechanics_to_games), + publishers_to_games: many(publishers_to_games), + gamesToExternalIds: many(gamesToExternalIds), +})); + +export const expansions = pgTable('expansions', { + id: varchar('id', { + length: 255 + }) + .primaryKey() + .$defaultFn(() => nanoid()), + base_game_id: varchar('base_game_id', { + length: 255 + }) + .notNull() + .references(() => games.id, { onDelete: 'cascade' }), + game_id: varchar('game_id', { + length: 255 + }) + .notNull() + .references(() => games.id, { onDelete: 'cascade' }), + created_at: timestamp('created_at', { + withTimezone: true, + mode: 'date', + precision: 6 + }).default(sql`now()`), + updated_at: timestamp('updated_at', { + withTimezone: true, + mode: 'date', + precision: 6 + }).default(sql`now()`) +}); + +export const expansionsToExternalIds = pgTable('expansions_to_external_ids', { + expansionId: varchar('expansion_id', { + length: 255 + }) + .notNull() + .references(() => expansions.id, { onDelete: 'cascade' }), + externalId: varchar('external_id', { + length: 255 + }) + .notNull() + .references(() => externalIds.id, { onDelete: 'cascade' }), +}); + +export const expansion_relations = relations(expansions, ({ one, many }) => ({ + baseGame: one(games, { + fields: [expansions.base_game_id], + references: [games.id] + }), + game: one(games, { + fields: [expansions.game_id], + references: [games.id] + }), + expansionsToExternalIds: many(expansionsToExternalIds) +})); + export const publishers = pgTable('publishers', { id: varchar('id', { length: 255 @@ -405,8 +427,22 @@ export const publishers = pgTable('publishers', { }).default(sql`now()`) }); +export const publishersToExternalIds = pgTable('publishers_to_external_ids', { + publisherId: varchar('publisher_id', { + length: 255 + }) + .notNull() + .references(() => publishers.id, { onDelete: 'cascade' }), + externalId: varchar('external_id', { + length: 255 + }) + .notNull() + .references(() => externalIds.id, { onDelete: 'cascade' }), +}); + export const publishers_relations = relations(publishers, ({ many }) => ({ - publishers_to_games: many(publishers_to_games) + publishers_to_games: many(publishers_to_games), + publishersToExternalIds: many(publishersToExternalIds) })); export const categories = pgTable('categories', { @@ -434,8 +470,42 @@ export const categories = pgTable('categories', { }).default(sql`now()`) }); +export const categoriesToExternalIds = pgTable('categories_to_external_ids', { + categoryId: varchar('category_id', { + length: 255 + }) + .notNull() + .references(() => categories.id, { onDelete: 'cascade' }), + externalId: varchar('external_id', { + length: 255 + }) + .notNull() + .references(() => externalIds.id, { onDelete: 'cascade' }), +}) + +export const categories_to_games = pgTable('categories_to_games', { + category_id: varchar('category_id', { + length: 255 + }), + game_id: varchar('game_id', { + length: 255 + }) +}); + +export const categories_to_games_relations = relations(categories_to_games, ({ one }) => ({ + category: one(categories, { + fields: [categories_to_games.category_id], + references: [categories.id] + }), + game: one(games, { + fields: [categories_to_games.game_id], + references: [games.id] + }) +})); + export const categories_relations = relations(categories, ({ many }) => ({ - categories_to_games: many(categories_to_games) + categories_to_games: many(categories_to_games), + categoriesToExternalIds: many(categoriesToExternalIds) })); export const mechanics = pgTable('mechanics', { @@ -463,126 +533,22 @@ export const mechanics = pgTable('mechanics', { }).default(sql`now()`) }); +export const mechanicsToExternalIds = pgTable('mechanics_to_external_ids', { + mechanicId: varchar('mechanic_id', { + length: 255 + }) + .notNull() + .references(() => mechanics.id, { onDelete: 'cascade' }), + externalId: varchar('external_id', { + length: 255 + }) + .notNull() + .references(() => externalIds.id, { onDelete: 'cascade' }), +}) + export const mechanic_relations = relations(mechanics, ({ many }) => ({ - mechanics_to_games: many(mechanics_to_games) -})); - -export const designers = pgTable('designers', { - id: varchar('id', { - length: 255 - }) - .primaryKey() - .$defaultFn(() => nanoid()), - name: varchar('name', { - length: 255 - }), - slug: varchar('slug', { - length: 255 - }), - external_id: integer('external_id'), - created_at: timestamp('created_at', { - withTimezone: true, - mode: 'date', - precision: 6 - }).default(sql`now()`), - updated_at: timestamp('updated_at', { - withTimezone: true, - mode: 'date', - precision: 6 - }).default(sql`now()`) -}); - -export const designers_relations = relations(designers, ({ many }) => ({ - designers_to_games: many(designers_to_games) -})); - -export const artists = pgTable('artists', { - id: varchar('id', { - length: 255 - }) - .primaryKey() - .$defaultFn(() => nanoid()), - name: varchar('name', { - length: 255 - }), - slug: varchar('slug', { - length: 255 - }), - external_id: integer('external_id'), - created_at: timestamp('created_at', { - withTimezone: true, - mode: 'date', - precision: 6 - }).default(sql`now()`), - updated_at: timestamp('updated_at', { - withTimezone: true, - mode: 'date', - precision: 6 - }).default(sql`now()`) -}); - -export const artists_relations = relations(artists, ({ many }) => ({ - artists_to_games: many(artists_to_games) -})); - -export const artists_to_games = pgTable('artists_to_games', { - artist_id: varchar('artist_id', { - length: 255 - }), - game_id: varchar('game_id', { - length: 255 - }) -}); - -export const artists_to_games_relations = relations(artists_to_games, ({ one }) => ({ - artist: one(artists, { - fields: [artists_to_games.artist_id], - references: [artists.id] - }), - game: one(games, { - fields: [artists_to_games.game_id], - references: [games.id] - }) -})); - -export const categories_to_games = pgTable('categories_to_games', { - category_id: varchar('category_id', { - length: 255 - }), - game_id: varchar('game_id', { - length: 255 - }) -}); - -export const categories_to_games_relations = relations(categories_to_games, ({ one }) => ({ - category: one(categories, { - fields: [categories_to_games.category_id], - references: [categories.id] - }), - game: one(games, { - fields: [categories_to_games.game_id], - references: [games.id] - }) -})); - -export const designers_to_games = pgTable('designers_to_games', { - designer_id: varchar('designer_id', { - length: 255 - }), - game_id: varchar('game_id', { - length: 255 - }) -}); - -export const designers_to_games_relations = relations(designers_to_games, ({ one }) => ({ - designer: one(designers, { - fields: [designers_to_games.designer_id], - references: [designers.id] - }), - game: one(games, { - fields: [designers_to_games.game_id], - references: [games.id] - }) + mechanics_to_games: many(mechanics_to_games), + mechanicsToExternalIds: many(mechanicsToExternalIds) })); export const mechanics_to_games = pgTable('mechanics_to_games', { diff --git a/src/seed.ts b/src/seed.ts new file mode 100644 index 0000000..d035833 --- /dev/null +++ b/src/seed.ts @@ -0,0 +1,29 @@ +import 'dotenv/config'; +import { drizzle } from "drizzle-orm/node-postgres"; +import pg from 'pg'; +import * as schema from './schema'; + +// create the connection +const pool = new pg.Pool({ + user: process.env.DATABASE_USER, + password: process.env.DATABASE_PASSWORD, + host: process.env.DATABASE_HOST, + port: new Number(process.env.DATABASE_PORT).valueOf(), + database: process.env.DATABASE_DB +}); + +const db = drizzle(pool, { schema: schema }); + +const existingRoles = await db.query.roles.findMany(); +console.log('Existing roles', existingRoles); +if (existingRoles.length === 0) { + console.log('Creating roles ...'); + await db.insert(schema.roles).values([{ + name: 'admin' + }, { + name: 'user' + }]); + console.log('Roles created.'); +} else { + console.log('Roles already exist. No action taken.'); +} diff --git a/src/seed/insert.ts b/src/seed/insert.ts deleted file mode 100644 index 1a1fd00..0000000 --- a/src/seed/insert.ts +++ /dev/null @@ -1,47 +0,0 @@ -import 'dotenv/config'; -import { drizzle } from "drizzle-orm/node-postgres"; -import { sql } from 'drizzle-orm'; -import pg from 'pg'; -import * as schema from '../schema'; - -// create the connection -const pool = new pg.Pool({ - user: process.env.DATABASE_USER, - password: process.env.DATABASE_PASSWORD, - host: process.env.DATABASE_HOST, - port: process.env.DATABASE_PORT, - database: process.env.DATABASE_DB -}); - -const db = drizzle(pool, { schema: schema }); - -const existingRoles = await db.query.roles.findMany(); -if (existingRoles.length === 0) { - console.log('Creating roles ...'); - await db.insert(schema.roles).values([{ - name: 'admin' - }, { - name: 'user' - }]); - console.log('Roles created.'); -} else { - console.log('Roles already exist. No action taken.'); -} - -const indexes = await db.execute(sql`select * from pg_catalog.pg_indexes where tablename = 'games'`); - -console.log('Indexes', indexes); - -const nameSlugIndexExists = indexes[0].flatMap((i) => i.Key_name).indexOf('full_text_name_slug_index') > -1; - -console.log('nameSlugIndexExists', nameSlugIndexExists); - -if (!nameSlugIndexExists) { - console.log('Full Text Index does not exist. Creating...'); - // Create index - await db.execute(sql`alter table games ADD FULLTEXT INDEX full_text_name_slug_index (name, slug)`); -} else { - console.log('Full Text Index already exists. No action taken.'); -} - -await connection.end();