From fe030b7726c7aba469c9a670cf6908e13f4d602c Mon Sep 17 00:00:00 2001
From: Gigi <47110839+DarthGigi@users.noreply.github.com>
Date: Thu, 29 Feb 2024 03:04:33 +0100
Subject: [PATCH 1/3] Update database schema and migrate to Supabase
---
.env.example | 4 +-
.../20240229000137_init/migration.sql | 168 ++++++++++++++++++
.../migration.sql | 160 +++++++++++++++++
.../migration.sql | 12 ++
.../migration.sql | 5 +
prisma/migrations/migration_lock.toml | 3 +
prisma/schema.prisma | 45 +++--
.../components/card/card-minion-amount.svelte | 4 +-
.../components/card/card-minion-price.svelte | 4 +-
src/lib/types.ts | 8 +-
.../(protected)/dashboard/+page.server.ts | 6 +-
.../dashboard/auctions/+page.server.ts | 2 +-
.../dashboard/auctions/data-table.svelte | 4 +-
.../dashboard/users/+page.server.ts | 2 +-
.../(protected)/profile/+page.server.ts | 6 +-
.../(main)/(protected)/profile/+page.svelte | 4 +-
.../(protected)/profile/chats/+page.server.ts | 2 -
src/routes/(main)/+page.server.ts | 6 +-
.../(shared)/[user=username]/+page.server.ts | 4 +-
.../[minionID]/+page.server.ts | 2 +-
.../dashboard/auctions/delete/+server.ts | 2 +-
src/routes/api/loadMinions/+server.ts | 3 +-
.../api/oauth/minecraft/+page.server.ts | 8 +-
src/routes/sitemap.xml/+server.ts | 2 +-
24 files changed, 399 insertions(+), 67 deletions(-)
create mode 100644 prisma/migrations/20240229000137_init/migration.sql
create mode 100644 prisma/migrations/20240229001449_remove_mongodb_map/migration.sql
create mode 100644 prisma/migrations/20240229005509_remove_unused_tables/migration.sql
create mode 100644 prisma/migrations/20240229012850_update_necessary_ints_to_big_ints/migration.sql
create mode 100644 prisma/migrations/migration_lock.toml
diff --git a/.env.example b/.env.example
index dac44f1..d04e6a3 100644
--- a/.env.example
+++ b/.env.example
@@ -1,8 +1,8 @@
# Database
# Prisma Accelerate
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__"
-# Direct MongoDB connection
-DIRECT_DATABASE_URL="mongodb://username:password@host[:port]/defaultauthdb?retryWrites=true&w=majority"
+# Direct Supabase / Postgres connection
+DIRECT_URL="postgres://postgres:[password]@db.[your-supabase-project].supabase.co:5432/postgres"
# mc-auth.com App
MC_AUTH_CLIENT_ID="123456789"
diff --git a/prisma/migrations/20240229000137_init/migration.sql b/prisma/migrations/20240229000137_init/migration.sql
new file mode 100644
index 0000000..781017c
--- /dev/null
+++ b/prisma/migrations/20240229000137_init/migration.sql
@@ -0,0 +1,168 @@
+-- CreateEnum
+CREATE TYPE "NotificationType" AS ENUM ('ALL', 'EMAIL', 'DEVICE', 'NONE');
+
+-- CreateTable
+CREATE TABLE "User" (
+ "_id" TEXT NOT NULL,
+ "loggedInAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "username" TEXT NOT NULL,
+ "avatar" TEXT NOT NULL,
+ "skin" TEXT NOT NULL,
+ "cape" TEXT,
+
+ CONSTRAINT "User_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateTable
+CREATE TABLE "UserSettings" (
+ "_id" TEXT NOT NULL,
+ "user_id" TEXT NOT NULL,
+
+ CONSTRAINT "UserSettings_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateTable
+CREATE TABLE "ProfileSettings" (
+ "_id" TEXT NOT NULL,
+ "email" TEXT,
+ "bio" TEXT,
+ "website" TEXT,
+
+ CONSTRAINT "ProfileSettings_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateTable
+CREATE TABLE "NotificationSettings" (
+ "_id" TEXT NOT NULL,
+ "notificationType" "NotificationType" NOT NULL,
+ "marketNotifications" BOOLEAN NOT NULL DEFAULT true,
+ "socialNotifications" BOOLEAN NOT NULL DEFAULT true,
+ "fcmTokens" TEXT[],
+
+ CONSTRAINT "NotificationSettings_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateTable
+CREATE TABLE "Session" (
+ "_id" TEXT NOT NULL,
+ "userId" TEXT NOT NULL,
+ "expiresAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "Session_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateTable
+CREATE TABLE "Key" (
+ "_id" TEXT NOT NULL,
+ "hashed_password" TEXT,
+ "user_id" TEXT NOT NULL,
+
+ CONSTRAINT "Key_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateTable
+CREATE TABLE "Minion" (
+ "_id" TEXT NOT NULL,
+ "name" TEXT NOT NULL,
+ "generator" TEXT NOT NULL,
+ "generator_tier" INTEGER NOT NULL,
+ "texture" TEXT NOT NULL,
+ "skin" TEXT NOT NULL,
+ "maxTier" INTEGER NOT NULL,
+ "craftCost" INTEGER NOT NULL DEFAULT 0,
+
+ CONSTRAINT "Minion_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateTable
+CREATE TABLE "Auction" (
+ "_id" TEXT NOT NULL,
+ "minion_id" TEXT NOT NULL,
+ "user_id" TEXT NOT NULL,
+ "hasInfusion" BOOLEAN NOT NULL DEFAULT false,
+ "price" DOUBLE PRECISION NOT NULL,
+ "amount" INTEGER,
+ "timeCreated" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+
+ CONSTRAINT "Auction_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateTable
+CREATE TABLE "Chat" (
+ "_id" TEXT NOT NULL,
+ "user1_id" TEXT NOT NULL,
+ "user2_id" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "user1Read" BOOLEAN NOT NULL DEFAULT false,
+ "user2Read" BOOLEAN NOT NULL DEFAULT false,
+
+ CONSTRAINT "Chat_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateTable
+CREATE TABLE "Message" (
+ "_id" TEXT NOT NULL,
+ "chat_id" TEXT NOT NULL,
+ "user_id" TEXT NOT NULL,
+ "content" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+
+ CONSTRAINT "Message_pkey" PRIMARY KEY ("_id")
+);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "UserSettings_user_id_key" ON "UserSettings"("user_id");
+
+-- CreateIndex
+CREATE INDEX "Session_userId_idx" ON "Session"("userId");
+
+-- CreateIndex
+CREATE INDEX "Key_user_id_idx" ON "Key"("user_id");
+
+-- CreateIndex
+CREATE INDEX "Auction_user_id_idx" ON "Auction"("user_id");
+
+-- CreateIndex
+CREATE INDEX "Auction_minion_id_idx" ON "Auction"("minion_id");
+
+-- CreateIndex
+CREATE INDEX "Message_chat_id_idx" ON "Message"("chat_id");
+
+-- CreateIndex
+CREATE INDEX "Message_user_id_idx" ON "Message"("user_id");
+
+-- AddForeignKey
+ALTER TABLE "UserSettings" ADD CONSTRAINT "UserSettings__id_fkey" FOREIGN KEY ("_id") REFERENCES "User"("_id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ProfileSettings" ADD CONSTRAINT "ProfileSettings__id_fkey" FOREIGN KEY ("_id") REFERENCES "UserSettings"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "NotificationSettings" ADD CONSTRAINT "NotificationSettings__id_fkey" FOREIGN KEY ("_id") REFERENCES "UserSettings"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Key" ADD CONSTRAINT "Key_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Auction" ADD CONSTRAINT "Auction_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Auction" ADD CONSTRAINT "Auction_minion_id_fkey" FOREIGN KEY ("minion_id") REFERENCES "Minion"("_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Chat" ADD CONSTRAINT "Chat_user1_id_fkey" FOREIGN KEY ("user1_id") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Chat" ADD CONSTRAINT "Chat_user2_id_fkey" FOREIGN KEY ("user2_id") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Message" ADD CONSTRAINT "Message_chat_id_fkey" FOREIGN KEY ("chat_id") REFERENCES "Chat"("_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Message" ADD CONSTRAINT "Message_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/migrations/20240229001449_remove_mongodb_map/migration.sql b/prisma/migrations/20240229001449_remove_mongodb_map/migration.sql
new file mode 100644
index 0000000..b910d6a
--- /dev/null
+++ b/prisma/migrations/20240229001449_remove_mongodb_map/migration.sql
@@ -0,0 +1,160 @@
+/*
+ Warnings:
+
+ - The primary key for the `Auction` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `Auction` table. All the data in the column will be lost.
+ - The primary key for the `Chat` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `Chat` table. All the data in the column will be lost.
+ - The primary key for the `Key` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `Key` table. All the data in the column will be lost.
+ - The primary key for the `Message` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `Message` table. All the data in the column will be lost.
+ - The primary key for the `Minion` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `Minion` table. All the data in the column will be lost.
+ - The primary key for the `NotificationSettings` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `NotificationSettings` table. All the data in the column will be lost.
+ - The primary key for the `ProfileSettings` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `ProfileSettings` table. All the data in the column will be lost.
+ - The primary key for the `Session` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `Session` table. All the data in the column will be lost.
+ - The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `User` table. All the data in the column will be lost.
+ - The primary key for the `UserSettings` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - You are about to drop the column `_id` on the `UserSettings` table. All the data in the column will be lost.
+ - The required column `id` was added to the `Auction` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.
+ - The required column `id` was added to the `Chat` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.
+ - Added the required column `id` to the `Key` table without a default value. This is not possible if the table is not empty.
+ - The required column `id` was added to the `Message` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.
+ - Added the required column `id` to the `Minion` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `id` to the `NotificationSettings` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `id` to the `ProfileSettings` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `id` to the `Session` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `id` to the `User` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `id` to the `UserSettings` table without a default value. This is not possible if the table is not empty.
+
+*/
+-- DropForeignKey
+ALTER TABLE "Auction" DROP CONSTRAINT "Auction_minion_id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Auction" DROP CONSTRAINT "Auction_user_id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Chat" DROP CONSTRAINT "Chat_user1_id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Chat" DROP CONSTRAINT "Chat_user2_id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Key" DROP CONSTRAINT "Key_user_id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Message" DROP CONSTRAINT "Message_chat_id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Message" DROP CONSTRAINT "Message_user_id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "NotificationSettings" DROP CONSTRAINT "NotificationSettings__id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "ProfileSettings" DROP CONSTRAINT "ProfileSettings__id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "UserSettings" DROP CONSTRAINT "UserSettings__id_fkey";
+
+-- AlterTable
+ALTER TABLE "Auction" DROP CONSTRAINT "Auction_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "Auction_pkey" PRIMARY KEY ("id");
+
+-- AlterTable
+ALTER TABLE "Chat" DROP CONSTRAINT "Chat_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "Chat_pkey" PRIMARY KEY ("id");
+
+-- AlterTable
+ALTER TABLE "Key" DROP CONSTRAINT "Key_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "Key_pkey" PRIMARY KEY ("id");
+
+-- AlterTable
+ALTER TABLE "Message" DROP CONSTRAINT "Message_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "Message_pkey" PRIMARY KEY ("id");
+
+-- AlterTable
+ALTER TABLE "Minion" DROP CONSTRAINT "Minion_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "Minion_pkey" PRIMARY KEY ("id");
+
+-- AlterTable
+ALTER TABLE "NotificationSettings" DROP CONSTRAINT "NotificationSettings_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "NotificationSettings_pkey" PRIMARY KEY ("id");
+
+-- AlterTable
+ALTER TABLE "ProfileSettings" DROP CONSTRAINT "ProfileSettings_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "ProfileSettings_pkey" PRIMARY KEY ("id");
+
+-- AlterTable
+ALTER TABLE "Session" DROP CONSTRAINT "Session_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "Session_pkey" PRIMARY KEY ("id");
+
+-- AlterTable
+ALTER TABLE "User" DROP CONSTRAINT "User_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id");
+
+-- AlterTable
+ALTER TABLE "UserSettings" DROP CONSTRAINT "UserSettings_pkey",
+DROP COLUMN "_id",
+ADD COLUMN "id" TEXT NOT NULL,
+ADD CONSTRAINT "UserSettings_pkey" PRIMARY KEY ("id");
+
+-- AddForeignKey
+ALTER TABLE "UserSettings" ADD CONSTRAINT "UserSettings_id_fkey" FOREIGN KEY ("id") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ProfileSettings" ADD CONSTRAINT "ProfileSettings_id_fkey" FOREIGN KEY ("id") REFERENCES "UserSettings"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "NotificationSettings" ADD CONSTRAINT "NotificationSettings_id_fkey" FOREIGN KEY ("id") REFERENCES "UserSettings"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Key" ADD CONSTRAINT "Key_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Auction" ADD CONSTRAINT "Auction_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Auction" ADD CONSTRAINT "Auction_minion_id_fkey" FOREIGN KEY ("minion_id") REFERENCES "Minion"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Chat" ADD CONSTRAINT "Chat_user1_id_fkey" FOREIGN KEY ("user1_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Chat" ADD CONSTRAINT "Chat_user2_id_fkey" FOREIGN KEY ("user2_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Message" ADD CONSTRAINT "Message_chat_id_fkey" FOREIGN KEY ("chat_id") REFERENCES "Chat"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Message" ADD CONSTRAINT "Message_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/migrations/20240229005509_remove_unused_tables/migration.sql b/prisma/migrations/20240229005509_remove_unused_tables/migration.sql
new file mode 100644
index 0000000..0d4aefc
--- /dev/null
+++ b/prisma/migrations/20240229005509_remove_unused_tables/migration.sql
@@ -0,0 +1,12 @@
+/*
+ Warnings:
+
+ - You are about to drop the column `avatar` on the `User` table. All the data in the column will be lost.
+ - You are about to drop the column `cape` on the `User` table. All the data in the column will be lost.
+ - You are about to drop the column `skin` on the `User` table. All the data in the column will be lost.
+
+*/
+-- AlterTable
+ALTER TABLE "User" DROP COLUMN "avatar",
+DROP COLUMN "cape",
+DROP COLUMN "skin";
diff --git a/prisma/migrations/20240229012850_update_necessary_ints_to_big_ints/migration.sql b/prisma/migrations/20240229012850_update_necessary_ints_to_big_ints/migration.sql
new file mode 100644
index 0000000..d29b41d
--- /dev/null
+++ b/prisma/migrations/20240229012850_update_necessary_ints_to_big_ints/migration.sql
@@ -0,0 +1,5 @@
+-- AlterTable
+ALTER TABLE "Auction" ALTER COLUMN "amount" SET DATA TYPE BIGINT;
+
+-- AlterTable
+ALTER TABLE "Minion" ALTER COLUMN "craftCost" SET DATA TYPE BIGINT;
diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml
new file mode 100644
index 0000000..fbffa92
--- /dev/null
+++ b/prisma/migrations/migration_lock.toml
@@ -0,0 +1,3 @@
+# Please do not edit this file manually
+# It should be added in your version-control system (i.e. Git)
+provider = "postgresql"
\ No newline at end of file
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 9fae5dc..d1ab08e 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -3,31 +3,26 @@
generator client {
provider = "prisma-client-js"
}
-
datasource db {
- provider = "mongodb"
+ provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
-
model User {
- id String @id @map("_id")
+ id String @id
sessions Session[]
key Key[]
- loggedInAt DateTime @default(now()) @updatedAt
- username String @unique
- avatar String
- skin String
- cape String?
- minions MinionSeller[]
- chatsAsUser1 Chat[] @relation("user1")
- chatsAsUser2 Chat[] @relation("user2")
+ loggedInAt DateTime @default(now()) @updatedAt
+ username String @unique
+ auctions Auction[]
+ chatsAsUser1 Chat[] @relation("user1")
+ chatsAsUser2 Chat[] @relation("user2")
messages Message[]
settings UserSettings?
}
model UserSettings {
- id String @id @map("_id")
+ id String @id
user_id String @unique
user User @relation(fields: [id], references: [id])
profileSettings ProfileSettings?
@@ -35,7 +30,7 @@ model UserSettings {
}
model ProfileSettings {
- id String @id @map("_id")
+ id String @id
userSettings UserSettings @relation(fields: [id], references: [user_id], onDelete: Cascade)
email String?
bio String?
@@ -50,7 +45,7 @@ enum NotificationType {
}
model NotificationSettings {
- id String @id @map("_id")
+ id String @id
userSettings UserSettings @relation(fields: [id], references: [user_id], onDelete: Cascade)
notificationType NotificationType
marketNotifications Boolean @default(true)
@@ -59,7 +54,7 @@ model NotificationSettings {
}
model Session {
- id String @id @map("_id")
+ id String @id
userId String
expiresAt DateTime
user User @relation(references: [id], fields: [userId], onDelete: Cascade)
@@ -68,7 +63,7 @@ model Session {
}
model Key {
- id String @id @map("_id")
+ id String @id
hashed_password String?
user_id String
user User @relation(references: [id], fields: [user_id], onDelete: Cascade)
@@ -77,26 +72,26 @@ model Key {
}
model Minion {
- id String @id @map("_id")
+ id String @id
name String
generator String
generator_tier Int
texture String
skin String
maxTier Int
- craftCost Int @default(0)
- sellers MinionSeller[]
+ craftCost Float @default(0)
+ sellers Auction[]
}
-model MinionSeller {
- id String @id @default(cuid()) @map("_id")
+model Auction {
+ id String @id @default(cuid())
minion_id String
user_id String
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
minion Minion @relation(fields: [minion_id], references: [id], onDelete: Cascade)
hasInfusion Boolean @default(false)
price Float
- amount Int?
+ amount BigInt?
timeCreated DateTime @default(now()) @updatedAt
@@index([user_id])
@@ -104,7 +99,7 @@ model MinionSeller {
}
model Chat {
- id String @id @default(cuid()) @map("_id")
+ id String @id @default(cuid())
user1_id String
user2_id String
user1 User @relation("user1", fields: [user1_id], references: [id], onDelete: Cascade)
@@ -116,7 +111,7 @@ model Chat {
}
model Message {
- id String @id @default(cuid()) @map("_id")
+ id String @id @default(cuid())
chat_id String
user_id String
content String
diff --git a/src/lib/components/card/card-minion-amount.svelte b/src/lib/components/card/card-minion-amount.svelte
index a8e640a..12c576a 100644
--- a/src/lib/components/card/card-minion-amount.svelte
+++ b/src/lib/components/card/card-minion-amount.svelte
@@ -1,7 +1,7 @@
diff --git a/src/lib/components/card/card-minion-price.svelte b/src/lib/components/card/card-minion-price.svelte
index 7762aa1..9c96b8f 100644
--- a/src/lib/components/card/card-minion-price.svelte
+++ b/src/lib/components/card/card-minion-price.svelte
@@ -1,9 +1,9 @@
diff --git a/src/lib/types.ts b/src/lib/types.ts
index 57dbf9c..ac3e932 100644
--- a/src/lib/types.ts
+++ b/src/lib/types.ts
@@ -1,11 +1,11 @@
-import type { Minion, MinionSeller, User } from "@prisma/client";
+import type { Minion, Auction, User } from "@prisma/client";
-// extend the MinionSeller type to include the user and minion
-interface Seller extends MinionSeller {
+// extend the Auction type to include the user and minion
+interface Seller extends Auction {
id: any;
timeCreated: string | number | Date;
user: User;
minion: Minion;
}
-export type { Minion, MinionSeller, Seller };
+export type { Minion, Auction, Seller };
diff --git a/src/routes/(main)/(protected)/dashboard/+page.server.ts b/src/routes/(main)/(protected)/dashboard/+page.server.ts
index a3575a4..b930971 100644
--- a/src/routes/(main)/(protected)/dashboard/+page.server.ts
+++ b/src/routes/(main)/(protected)/dashboard/+page.server.ts
@@ -11,13 +11,13 @@ export const load = (async ({ locals }) => {
},
where: {
id: {
- not: locals.user.id
+ not: locals.user!.id
}
},
take: MAX_ITEMS
}),
- prisma.minionSeller.count(),
- prisma.minionSeller.findMany({
+ prisma.auction.count(),
+ prisma.auction.findMany({
orderBy: {
timeCreated: "desc"
},
diff --git a/src/routes/(main)/(protected)/dashboard/auctions/+page.server.ts b/src/routes/(main)/(protected)/dashboard/auctions/+page.server.ts
index 7273d01..ebe92e8 100644
--- a/src/routes/(main)/(protected)/dashboard/auctions/+page.server.ts
+++ b/src/routes/(main)/(protected)/dashboard/auctions/+page.server.ts
@@ -2,7 +2,7 @@ import type { PageServerLoad } from "./$types";
export const load = (async () => {
const [auctions] = await Promise.all([
- prisma.minionSeller.findMany({
+ prisma.auction.findMany({
include: {
user: true,
minion: true
diff --git a/src/routes/(main)/(protected)/dashboard/auctions/data-table.svelte b/src/routes/(main)/(protected)/dashboard/auctions/data-table.svelte
index f2d77d3..d0c5cde 100644
--- a/src/routes/(main)/(protected)/dashboard/auctions/data-table.svelte
+++ b/src/routes/(main)/(protected)/dashboard/auctions/data-table.svelte
@@ -7,7 +7,7 @@
import * as Table from "$lib/components/ui/table";
import { preferences } from "$lib/stores/preferences";
import { formatNumber } from "$lib/utilities";
- import type { MinionSeller } from "@prisma/client";
+ import type { Auction } from "@prisma/client";
import ArrowUpDown from "lucide-svelte/icons/arrow-up-down";
import ChevronDown from "lucide-svelte/icons/chevron-down";
import CircleEllipsis from "lucide-svelte/icons/circle-ellipsis";
@@ -21,7 +21,7 @@
import DataTableMinion from "./data-table-minion.svelte";
import DataTableUser from "./data-table-user.svelte";
- export let data: MinionSeller[];
+ export let data: Auction[];
const table = createTable(readable(data), {
page: addPagination(),
sort: addSortBy({ disableMultiSort: true }),
diff --git a/src/routes/(main)/(protected)/dashboard/users/+page.server.ts b/src/routes/(main)/(protected)/dashboard/users/+page.server.ts
index ec0720a..1cd37fc 100644
--- a/src/routes/(main)/(protected)/dashboard/users/+page.server.ts
+++ b/src/routes/(main)/(protected)/dashboard/users/+page.server.ts
@@ -6,7 +6,7 @@ export const load = (async () => {
include: {
_count: {
select: {
- minions: true
+ auctions: true
}
}
}
diff --git a/src/routes/(main)/(protected)/profile/+page.server.ts b/src/routes/(main)/(protected)/profile/+page.server.ts
index a7de876..91dc84c 100644
--- a/src/routes/(main)/(protected)/profile/+page.server.ts
+++ b/src/routes/(main)/(protected)/profile/+page.server.ts
@@ -23,7 +23,7 @@ export const load = (async ({ locals }) => {
generator: "asc"
}
}),
- userMinions: prisma.minionSeller.findMany({
+ userMinions: prisma.auction.findMany({
where: {
user: {
id: locals.user!.id
@@ -80,7 +80,7 @@ export const actions = {
// create the minion in the database
try {
- const createdMinion = await prisma.minionSeller.create({
+ const createdMinion = await prisma.auction.create({
data: {
amount: formCreate.data.amount,
price: Number(formCreate.data.price),
@@ -118,7 +118,7 @@ export const actions = {
const minionId = formDelete.data.id as string;
try {
- const deletedMinion = await prisma.minionSeller.delete({
+ const deletedMinion = await prisma.auction.delete({
where: {
id: minionId,
AND: [
diff --git a/src/routes/(main)/(protected)/profile/+page.svelte b/src/routes/(main)/(protected)/profile/+page.svelte
index 19738be..23fd249 100644
--- a/src/routes/(main)/(protected)/profile/+page.svelte
+++ b/src/routes/(main)/(protected)/profile/+page.svelte
@@ -13,7 +13,7 @@
import { Label } from "$lib/components/ui/label";
import { Switch } from "$lib/components/ui/switch";
import { formatNumber } from "$lib/utilities";
- import type { Minion, MinionSeller as Seller, User } from "@prisma/client";
+ import type { Minion, Auction, User } from "@prisma/client";
import ChevronsUpDown from "lucide-svelte/icons/chevrons-up-down";
import Cog from "lucide-svelte/icons/cog";
import Loader2 from "lucide-svelte/icons/loader-2";
@@ -87,7 +87,7 @@
$: moreThan1 = $formDataCreate.amount > (parseInt($constraintsCreate.amount?.min?.toString() ?? "0") || 0);
let showDeleteFormDialog = false;
- let minionToDelete: Seller & { minion: Minion } & { user: User };
+ let minionToDelete: Auction & { minion: Minion } & { user: User };
let minecraftAvatar: HTMLCanvasElement;
let minecraftAvatarContainer: HTMLDivElement;
diff --git a/src/routes/(main)/(protected)/profile/chats/+page.server.ts b/src/routes/(main)/(protected)/profile/chats/+page.server.ts
index 86cffa2..2b03876 100644
--- a/src/routes/(main)/(protected)/profile/chats/+page.server.ts
+++ b/src/routes/(main)/(protected)/profile/chats/+page.server.ts
@@ -27,7 +27,6 @@ export const load = (async ({ locals }) => {
select: {
id: true,
username: true,
- avatar: true,
loggedInAt: true
}
},
@@ -35,7 +34,6 @@ export const load = (async ({ locals }) => {
select: {
id: true,
username: true,
- avatar: true,
loggedInAt: true
}
},
diff --git a/src/routes/(main)/+page.server.ts b/src/routes/(main)/+page.server.ts
index 6ead1b6..374a34c 100644
--- a/src/routes/(main)/+page.server.ts
+++ b/src/routes/(main)/+page.server.ts
@@ -5,7 +5,7 @@ export const load = (async ({ locals }) => {
if (locals.maintenance) return;
return {
- minions: prisma.minionSeller.findMany({
+ minions: prisma.auction.findMany({
take: 18,
skip: 0,
orderBy: [
@@ -20,11 +20,9 @@ export const load = (async ({ locals }) => {
minion: true,
user: {
select: {
- avatar: true,
id: true,
loggedInAt: true,
- username: true,
- skin: true
+ username: true
}
}
}
diff --git a/src/routes/(shared)/[user=username]/+page.server.ts b/src/routes/(shared)/[user=username]/+page.server.ts
index 31bb6c2..5173ba1 100644
--- a/src/routes/(shared)/[user=username]/+page.server.ts
+++ b/src/routes/(shared)/[user=username]/+page.server.ts
@@ -9,7 +9,7 @@ export const load = (async ({ params, fetch }) => {
username: username
},
include: {
- minions: true
+ auctions: true
}
});
@@ -17,7 +17,7 @@ export const load = (async ({ params, fetch }) => {
redirect(302, "/");
}
- const minions = prisma.minionSeller.findMany({
+ const minions = prisma.auction.findMany({
where: {
user: {
id: minionuser.id
diff --git a/src/routes/(shared)/[user=username]/[minionID]/+page.server.ts b/src/routes/(shared)/[user=username]/[minionID]/+page.server.ts
index fbd9152..587e213 100644
--- a/src/routes/(shared)/[user=username]/[minionID]/+page.server.ts
+++ b/src/routes/(shared)/[user=username]/[minionID]/+page.server.ts
@@ -5,7 +5,7 @@ export const load = (async ({ params, fetch }) => {
const minionID = params.minionID;
const username = params.user;
- const userMinion = await prisma.minionSeller.findUnique({
+ const userMinion = await prisma.auction.findUnique({
where: {
id: minionID,
AND: [
diff --git a/src/routes/api/(protected)/dashboard/auctions/delete/+server.ts b/src/routes/api/(protected)/dashboard/auctions/delete/+server.ts
index df55ff6..84fe4cd 100644
--- a/src/routes/api/(protected)/dashboard/auctions/delete/+server.ts
+++ b/src/routes/api/(protected)/dashboard/auctions/delete/+server.ts
@@ -6,7 +6,7 @@ export const DELETE: RequestHandler = async ({ request }) => {
const ids = data.ids as string[];
- await prisma.minionSeller.deleteMany({
+ await prisma.auction.deleteMany({
where: {
id: {
in: ids
diff --git a/src/routes/api/loadMinions/+server.ts b/src/routes/api/loadMinions/+server.ts
index 2622329..90659dd 100644
--- a/src/routes/api/loadMinions/+server.ts
+++ b/src/routes/api/loadMinions/+server.ts
@@ -11,7 +11,7 @@ type Params = {
};
async function getMinions(take: number = 18, skip?: number, orderBy: object = [{ timeCreated: "desc" }, { price: "asc" }], distinct?: any, where?: any) {
- let minions = await prisma.minionSeller.findMany({
+ let minions = await prisma.auction.findMany({
take,
skip,
orderBy,
@@ -21,7 +21,6 @@ async function getMinions(take: number = 18, skip?: number, orderBy: object = [{
minion: true,
user: {
select: {
- avatar: true,
id: true,
loggedInAt: true,
username: true
diff --git a/src/routes/api/oauth/minecraft/+page.server.ts b/src/routes/api/oauth/minecraft/+page.server.ts
index 9a4a427..b587ff6 100644
--- a/src/routes/api/oauth/minecraft/+page.server.ts
+++ b/src/routes/api/oauth/minecraft/+page.server.ts
@@ -180,10 +180,7 @@ export const load = (async ({ cookies, url, locals }) => {
id: existingUser.id
},
data: {
- username: minecraftUser.name,
- avatar: "",
- skin: "",
- cape: ""
+ username: minecraftUser.name
}
});
return existingUser;
@@ -195,9 +192,6 @@ export const load = (async ({ cookies, url, locals }) => {
data: {
id: minecraftUser.id,
username: minecraftUser.name,
- avatar: "",
- skin: "",
- cape: "",
loggedInAt: new Date(),
key: {
createMany: {
diff --git a/src/routes/sitemap.xml/+server.ts b/src/routes/sitemap.xml/+server.ts
index cfdc2fb..e179c93 100644
--- a/src/routes/sitemap.xml/+server.ts
+++ b/src/routes/sitemap.xml/+server.ts
@@ -10,7 +10,7 @@ export const GET: RequestHandler = async () => {
username: true
}
}),
- prisma.minionSeller.findMany({
+ prisma.auction.findMany({
select: {
id: true,
user: {
From b8a7aeb490a1fc19bc1ff91f1b552fbcd85a5fcc Mon Sep 17 00:00:00 2001
From: Gigi <47110839+DarthGigi@users.noreply.github.com>
Date: Thu, 29 Feb 2024 03:17:08 +0100
Subject: [PATCH 2/3] Change data type of 'amount' field in Auction model from
BigInt to Int
---
prisma/schema.prisma | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index d1ab08e..7659823 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -91,7 +91,7 @@ model Auction {
minion Minion @relation(fields: [minion_id], references: [id], onDelete: Cascade)
hasInfusion Boolean @default(false)
price Float
- amount BigInt?
+ amount Int
timeCreated DateTime @default(now()) @updatedAt
@@index([user_id])
From 0b98f5ae89ac4b8111f1c5b65785496c617f19a7 Mon Sep 17 00:00:00 2001
From: Gigi <47110839+DarthGigi@users.noreply.github.com>
Date: Thu, 29 Feb 2024 03:17:39 +0100
Subject: [PATCH 3/3] Fix preventDefault in delete button click event
---
src/routes/(main)/(protected)/profile/+page.svelte | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/routes/(main)/(protected)/profile/+page.svelte b/src/routes/(main)/(protected)/profile/+page.svelte
index 23fd249..40ba5f2 100644
--- a/src/routes/(main)/(protected)/profile/+page.svelte
+++ b/src/routes/(main)/(protected)/profile/+page.svelte
@@ -380,8 +380,8 @@
{
- preventDefault();
+ on:click={(e) => {
+ e.preventDefault();
submitDelete();
}}>
{#if !$submittingDelete}