-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update database schema and migrate to Supabase (#88)
- Loading branch information
Showing
24 changed files
with
401 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
160 changes: 160 additions & 0 deletions
160
prisma/migrations/20240229001449_remove_mongodb_map/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20240229005509_remove_unused_tables/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; |
5 changes: 5 additions & 0 deletions
5
prisma/migrations/20240229012850_update_necessary_ints_to_big_ints/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
Oops, something went wrong.