diff --git a/drizzle/0000_fixed_tomas.sql b/drizzle/0000_fixed_tomas.sql new file mode 100644 index 0000000..8c300c0 --- /dev/null +++ b/drizzle/0000_fixed_tomas.sql @@ -0,0 +1,113 @@ +CREATE TABLE "classes" ( + "id" bigint PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "balance" bigint DEFAULT 0, + "role_id" varchar(255), + CONSTRAINT "classes_name_unique" UNIQUE("name") +); +--> statement-breakpoint +CREATE TABLE "inventory" ( + "user_id" bigint NOT NULL, + "item_id" integer NOT NULL, + "quantity" bigint DEFAULT 1, + CONSTRAINT "inventory_user_id_item_id_pk" PRIMARY KEY("user_id","item_id"), + CONSTRAINT "quantity_check" CHECK ("inventory"."quantity" > 0) +); +--> statement-breakpoint +CREATE TABLE "item_transactions" ( + "id" bigserial PRIMARY KEY NOT NULL, + "user_id" bigint NOT NULL, + "related_user_id" bigint, + "item_id" integer NOT NULL, + "quantity" bigint NOT NULL, + "type" varchar(50) NOT NULL, + "description" text, + "created_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE "items" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "description" text, + "rarity" varchar(20) DEFAULT 'Common', + "type" varchar(50) DEFAULT 'MATERIAL' NOT NULL, + "usage_data" jsonb DEFAULT '{}'::jsonb, + "price" bigint, + "icon_url" text NOT NULL, + "image_url" text NOT NULL, + CONSTRAINT "items_name_unique" UNIQUE("name") +); +--> statement-breakpoint +CREATE TABLE "lootdrops" ( + "message_id" varchar(255) PRIMARY KEY NOT NULL, + "channel_id" varchar(255) NOT NULL, + "reward_amount" integer NOT NULL, + "currency" varchar(50) NOT NULL, + "claimed_by" bigint, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + "expires_at" timestamp with time zone +); +--> statement-breakpoint +CREATE TABLE "quests" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "description" text, + "trigger_event" varchar(50) NOT NULL, + "requirements" jsonb DEFAULT '{}'::jsonb NOT NULL, + "rewards" jsonb DEFAULT '{}'::jsonb NOT NULL +); +--> statement-breakpoint +CREATE TABLE "transactions" ( + "id" bigserial PRIMARY KEY NOT NULL, + "user_id" bigint, + "related_user_id" bigint, + "amount" bigint NOT NULL, + "type" varchar(50) NOT NULL, + "description" text, + "created_at" timestamp with time zone DEFAULT now() +); +--> statement-breakpoint +CREATE TABLE "user_quests" ( + "user_id" bigint NOT NULL, + "quest_id" integer NOT NULL, + "progress" integer DEFAULT 0, + "completed_at" timestamp with time zone, + CONSTRAINT "user_quests_user_id_quest_id_pk" PRIMARY KEY("user_id","quest_id") +); +--> statement-breakpoint +CREATE TABLE "user_timers" ( + "user_id" bigint NOT NULL, + "type" varchar(50) NOT NULL, + "key" varchar(100) NOT NULL, + "expires_at" timestamp with time zone NOT NULL, + "metadata" jsonb DEFAULT '{}'::jsonb, + CONSTRAINT "user_timers_user_id_type_key_pk" PRIMARY KEY("user_id","type","key") +); +--> statement-breakpoint +CREATE TABLE "users" ( + "id" bigint PRIMARY KEY NOT NULL, + "class_id" bigint, + "username" varchar(255) NOT NULL, + "is_active" boolean DEFAULT true, + "balance" bigint DEFAULT 0, + "xp" bigint DEFAULT 0, + "level" integer DEFAULT 1, + "daily_streak" integer DEFAULT 0, + "settings" jsonb DEFAULT '{}'::jsonb, + "created_at" timestamp with time zone DEFAULT now(), + "updated_at" timestamp with time zone DEFAULT now(), + CONSTRAINT "users_username_unique" UNIQUE("username") +); +--> statement-breakpoint +ALTER TABLE "inventory" ADD CONSTRAINT "inventory_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "inventory" ADD CONSTRAINT "inventory_item_id_items_id_fk" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "item_transactions" ADD CONSTRAINT "item_transactions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "item_transactions" ADD CONSTRAINT "item_transactions_related_user_id_users_id_fk" FOREIGN KEY ("related_user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "item_transactions" ADD CONSTRAINT "item_transactions_item_id_items_id_fk" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "lootdrops" ADD CONSTRAINT "lootdrops_claimed_by_users_id_fk" FOREIGN KEY ("claimed_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "transactions" ADD CONSTRAINT "transactions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "transactions" ADD CONSTRAINT "transactions_related_user_id_users_id_fk" FOREIGN KEY ("related_user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "user_quests" ADD CONSTRAINT "user_quests_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "user_quests" ADD CONSTRAINT "user_quests_quest_id_quests_id_fk" FOREIGN KEY ("quest_id") REFERENCES "public"."quests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "user_timers" ADD CONSTRAINT "user_timers_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "users" ADD CONSTRAINT "users_class_id_classes_id_fk" FOREIGN KEY ("class_id") REFERENCES "public"."classes"("id") ON DELETE no action 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..b1e1b76 --- /dev/null +++ b/drizzle/meta/0000_snapshot.json @@ -0,0 +1,770 @@ +{ + "id": "d43c3f7b-afe5-4974-ab67-fcd69256f3d8", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.classes": { + "name": "classes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "balance": { + "name": "balance", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": "0" + }, + "role_id": { + "name": "role_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "classes_name_unique": { + "name": "classes_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.inventory": { + "name": "inventory", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": "1" + } + }, + "indexes": {}, + "foreignKeys": { + "inventory_user_id_users_id_fk": { + "name": "inventory_user_id_users_id_fk", + "tableFrom": "inventory", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "inventory_item_id_items_id_fk": { + "name": "inventory_item_id_items_id_fk", + "tableFrom": "inventory", + "tableTo": "items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "inventory_user_id_item_id_pk": { + "name": "inventory_user_id_item_id_pk", + "columns": [ + "user_id", + "item_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "quantity_check": { + "name": "quantity_check", + "value": "\"inventory\".\"quantity\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.item_transactions": { + "name": "item_transactions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "related_user_id": { + "name": "related_user_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "item_id": { + "name": "item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_transactions_user_id_users_id_fk": { + "name": "item_transactions_user_id_users_id_fk", + "tableFrom": "item_transactions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "item_transactions_related_user_id_users_id_fk": { + "name": "item_transactions_related_user_id_users_id_fk", + "tableFrom": "item_transactions", + "tableTo": "users", + "columnsFrom": [ + "related_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "item_transactions_item_id_items_id_fk": { + "name": "item_transactions_item_id_items_id_fk", + "tableFrom": "item_transactions", + "tableTo": "items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.items": { + "name": "items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rarity": { + "name": "rarity", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "default": "'Common'" + }, + "type": { + "name": "type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'MATERIAL'" + }, + "usage_data": { + "name": "usage_data", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "price": { + "name": "price", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "icon_url": { + "name": "icon_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "image_url": { + "name": "image_url", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "items_name_unique": { + "name": "items_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lootdrops": { + "name": "lootdrops", + "schema": "", + "columns": { + "message_id": { + "name": "message_id", + "type": "varchar(255)", + "primaryKey": true, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "reward_amount": { + "name": "reward_amount", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "claimed_by": { + "name": "claimed_by", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "lootdrops_claimed_by_users_id_fk": { + "name": "lootdrops_claimed_by_users_id_fk", + "tableFrom": "lootdrops", + "tableTo": "users", + "columnsFrom": [ + "claimed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.quests": { + "name": "quests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "trigger_event": { + "name": "trigger_event", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "requirements": { + "name": "requirements", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "rewards": { + "name": "rewards", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.transactions": { + "name": "transactions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "related_user_id": { + "name": "related_user_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "transactions_user_id_users_id_fk": { + "name": "transactions_user_id_users_id_fk", + "tableFrom": "transactions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "transactions_related_user_id_users_id_fk": { + "name": "transactions_related_user_id_users_id_fk", + "tableFrom": "transactions", + "tableTo": "users", + "columnsFrom": [ + "related_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_quests": { + "name": "user_quests", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "quest_id": { + "name": "quest_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "progress": { + "name": "progress", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "user_quests_user_id_users_id_fk": { + "name": "user_quests_user_id_users_id_fk", + "tableFrom": "user_quests", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_quests_quest_id_quests_id_fk": { + "name": "user_quests_quest_id_quests_id_fk", + "tableFrom": "user_quests", + "tableTo": "quests", + "columnsFrom": [ + "quest_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "user_quests_user_id_quest_id_pk": { + "name": "user_quests_user_id_quest_id_pk", + "columns": [ + "user_id", + "quest_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_timers": { + "name": "user_timers", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + } + }, + "indexes": {}, + "foreignKeys": { + "user_timers_user_id_users_id_fk": { + "name": "user_timers_user_id_users_id_fk", + "tableFrom": "user_timers", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "user_timers_user_id_type_key_pk": { + "name": "user_timers_user_id_type_key_pk", + "columns": [ + "user_id", + "type", + "key" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "class_id": { + "name": "class_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "username": { + "name": "username", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "balance": { + "name": "balance", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": "0" + }, + "xp": { + "name": "xp", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": "0" + }, + "level": { + "name": "level", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "daily_streak": { + "name": "daily_streak", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "settings": { + "name": "settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "users_class_id_classes_id_fk": { + "name": "users_class_id_classes_id_fk", + "tableFrom": "users", + "tableTo": "classes", + "columnsFrom": [ + "class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_username_unique": { + "name": "users_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json new file mode 100644 index 0000000..e08da8a --- /dev/null +++ b/drizzle/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "7", + "dialect": "postgresql", + "entries": [ + { + "idx": 0, + "version": "7", + "when": 1766137924760, + "tag": "0000_fixed_tomas", + "breakpoints": true + } + ] +} \ No newline at end of file