diff --git a/packages/server/prisma/dbml/schema.dbml b/packages/server/prisma/dbml/schema.dbml index 94e783d..b47549b 100644 --- a/packages/server/prisma/dbml/schema.dbml +++ b/packages/server/prisma/dbml/schema.dbml @@ -10,7 +10,7 @@ Table User { FactionMember FactionMember [not null] } -Table PalleteColor { +Table PaletteColor { id Int [pk, increment] name String [not null] hex String [unique, not null] @@ -25,7 +25,7 @@ Table Pixel { color String [not null] createdAt DateTime [default: `now()`, not null] user User [not null] - pallete PalleteColor [not null] + pallete PaletteColor [not null] } Table Faction { @@ -82,7 +82,7 @@ Table FactionSettingDefinition { Ref: Pixel.userId > User.sub -Ref: Pixel.color > PalleteColor.hex +Ref: Pixel.color > PaletteColor.hex Ref: FactionMember.sub > User.sub diff --git a/packages/server/prisma/migrations/20230929223730_init/migration.sql b/packages/server/prisma/migrations/20230929223730_init/migration.sql deleted file mode 100644 index 9da11be..0000000 --- a/packages/server/prisma/migrations/20230929223730_init/migration.sql +++ /dev/null @@ -1,27 +0,0 @@ --- CreateTable -CREATE TABLE "User" ( - "sub" TEXT NOT NULL PRIMARY KEY, - "lastPixelTime" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP -); - --- CreateTable -CREATE TABLE "PalleteColor" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "name" TEXT NOT NULL, - "hex" TEXT NOT NULL -); - --- CreateTable -CREATE TABLE "Pixel" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "userId" TEXT NOT NULL, - "x" INTEGER NOT NULL, - "y" INTEGER NOT NULL, - "color" TEXT NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT "Pixel_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("sub") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "Pixel_color_fkey" FOREIGN KEY ("color") REFERENCES "PalleteColor" ("hex") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateIndex -CREATE UNIQUE INDEX "PalleteColor_hex_key" ON "PalleteColor"("hex"); diff --git a/packages/server/prisma/migrations/20240304215631_/migration.sql b/packages/server/prisma/migrations/20240304215631_/migration.sql deleted file mode 100644 index ab4deb2..0000000 --- a/packages/server/prisma/migrations/20240304215631_/migration.sql +++ /dev/null @@ -1,52 +0,0 @@ --- CreateTable -CREATE TABLE "Faction" ( - "id" TEXT NOT NULL PRIMARY KEY, - "name" TEXT NOT NULL, - "image" TEXT -); - --- CreateTable -CREATE TABLE "FactionMember" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "sub" TEXT NOT NULL, - "factionId" TEXT NOT NULL, - CONSTRAINT "FactionMember_sub_fkey" FOREIGN KEY ("sub") REFERENCES "User" ("sub") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "FactionMember_factionId_fkey" FOREIGN KEY ("factionId") REFERENCES "Faction" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "FactionRole" ( - "id" TEXT NOT NULL PRIMARY KEY, - "name" TEXT NOT NULL, - "level" INTEGER NOT NULL, - "factionId" TEXT NOT NULL, - CONSTRAINT "FactionRole_factionId_fkey" FOREIGN KEY ("factionId") REFERENCES "Faction" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "FactionSocial" ( - "id" TEXT NOT NULL PRIMARY KEY, - "factionId" TEXT NOT NULL, - "title" TEXT, - "url" TEXT NOT NULL, - "position" INTEGER NOT NULL, - CONSTRAINT "FactionSocial_factionId_fkey" FOREIGN KEY ("factionId") REFERENCES "Faction" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "FactionSetting" ( - "id" TEXT NOT NULL PRIMARY KEY, - "factionId" TEXT NOT NULL, - "key" TEXT NOT NULL, - "value" TEXT NOT NULL, - CONSTRAINT "FactionSetting_key_fkey" FOREIGN KEY ("key") REFERENCES "FactionSettingDefinition" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "FactionSetting_factionId_fkey" FOREIGN KEY ("factionId") REFERENCES "Faction" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "FactionSettingDefinition" ( - "id" TEXT NOT NULL PRIMARY KEY, - "name" TEXT NOT NULL, - "type" TEXT NOT NULL, - "minimumLevel" INTEGER NOT NULL -); diff --git a/packages/server/prisma/migrations/20240304220059_/migration.sql b/packages/server/prisma/migrations/20240304220059_/migration.sql deleted file mode 100644 index af33977..0000000 --- a/packages/server/prisma/migrations/20240304220059_/migration.sql +++ /dev/null @@ -1,12 +0,0 @@ --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_User" ( - "sub" TEXT NOT NULL PRIMARY KEY, - "lastPixelTime" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "pixelStack" INTEGER NOT NULL DEFAULT 0 -); -INSERT INTO "new_User" ("lastPixelTime", "sub") SELECT "lastPixelTime", "sub" FROM "User"; -DROP TABLE "User"; -ALTER TABLE "new_User" RENAME TO "User"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/packages/server/prisma/migrations/20240312015201_init/migration.sql b/packages/server/prisma/migrations/20240312015201_init/migration.sql new file mode 100644 index 0000000..99239dd --- /dev/null +++ b/packages/server/prisma/migrations/20240312015201_init/migration.sql @@ -0,0 +1,115 @@ +-- CreateTable +CREATE TABLE "User" ( + "sub" TEXT NOT NULL, + "lastPixelTime" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "pixelStack" INTEGER NOT NULL DEFAULT 0, + + CONSTRAINT "User_pkey" PRIMARY KEY ("sub") +); + +-- CreateTable +CREATE TABLE "PaletteColor" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "hex" TEXT NOT NULL, + + CONSTRAINT "PaletteColor_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Pixel" ( + "id" SERIAL NOT NULL, + "userId" TEXT NOT NULL, + "x" INTEGER NOT NULL, + "y" INTEGER NOT NULL, + "color" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Pixel_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Faction" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "image" TEXT, + + CONSTRAINT "Faction_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "FactionMember" ( + "id" SERIAL NOT NULL, + "sub" TEXT NOT NULL, + "factionId" TEXT NOT NULL, + + CONSTRAINT "FactionMember_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "FactionRole" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "level" INTEGER NOT NULL, + "factionId" TEXT NOT NULL, + + CONSTRAINT "FactionRole_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "FactionSocial" ( + "id" TEXT NOT NULL, + "factionId" TEXT NOT NULL, + "title" TEXT, + "url" TEXT NOT NULL, + "position" INTEGER NOT NULL, + + CONSTRAINT "FactionSocial_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "FactionSetting" ( + "id" TEXT NOT NULL, + "factionId" TEXT NOT NULL, + "key" TEXT NOT NULL, + "value" TEXT NOT NULL, + + CONSTRAINT "FactionSetting_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "FactionSettingDefinition" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "type" TEXT NOT NULL, + "minimumLevel" INTEGER NOT NULL, + + CONSTRAINT "FactionSettingDefinition_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "PaletteColor_hex_key" ON "PaletteColor"("hex"); + +-- AddForeignKey +ALTER TABLE "Pixel" ADD CONSTRAINT "Pixel_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("sub") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Pixel" ADD CONSTRAINT "Pixel_color_fkey" FOREIGN KEY ("color") REFERENCES "PaletteColor"("hex") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "FactionMember" ADD CONSTRAINT "FactionMember_sub_fkey" FOREIGN KEY ("sub") REFERENCES "User"("sub") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "FactionMember" ADD CONSTRAINT "FactionMember_factionId_fkey" FOREIGN KEY ("factionId") REFERENCES "Faction"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "FactionRole" ADD CONSTRAINT "FactionRole_factionId_fkey" FOREIGN KEY ("factionId") REFERENCES "Faction"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "FactionSocial" ADD CONSTRAINT "FactionSocial_factionId_fkey" FOREIGN KEY ("factionId") REFERENCES "Faction"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "FactionSetting" ADD CONSTRAINT "FactionSetting_key_fkey" FOREIGN KEY ("key") REFERENCES "FactionSettingDefinition"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "FactionSetting" ADD CONSTRAINT "FactionSetting_factionId_fkey" FOREIGN KEY ("factionId") REFERENCES "Faction"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/packages/server/prisma/migrations/migration_lock.toml b/packages/server/prisma/migrations/migration_lock.toml index e5e5c47..fbffa92 100644 --- a/packages/server/prisma/migrations/migration_lock.toml +++ b/packages/server/prisma/migrations/migration_lock.toml @@ -1,3 +1,3 @@ # Please do not edit this file manually # It should be added in your version-control system (i.e. Git) -provider = "sqlite" \ No newline at end of file +provider = "postgresql" \ No newline at end of file diff --git a/packages/server/prisma/schema.prisma b/packages/server/prisma/schema.prisma index 7114f93..9bfab93 100644 --- a/packages/server/prisma/schema.prisma +++ b/packages/server/prisma/schema.prisma @@ -10,7 +10,7 @@ generator dbml { } datasource db { - provider = "sqlite" + provider = "postgresql" url = env("DATABASE_URL") } @@ -23,8 +23,7 @@ model User { FactionMember FactionMember[] } -// TODO: i cannot spell, rename this to PaletteColor -model PalleteColor { +model PaletteColor { id Int @id @default(autoincrement()) name String hex String @unique @@ -42,7 +41,7 @@ model Pixel { createdAt DateTime @default(now()) user User @relation(fields: [userId], references: [sub]) - pallete PalleteColor @relation(fields: [color], references: [hex]) + pallete PaletteColor @relation(fields: [color], references: [hex]) } model Faction { diff --git a/packages/server/src/lib/SocketServer.ts b/packages/server/src/lib/SocketServer.ts index 4244056..d8ba892 100644 --- a/packages/server/src/lib/SocketServer.ts +++ b/packages/server/src/lib/SocketServer.ts @@ -5,11 +5,11 @@ import { Pixel, ServerToClientEvents, } from "@sc07-canvas/lib/src/net"; -import { CanvasLib } from "@sc07-canvas/lib/src/canvas"; +import { CanvasLib } from "@sc07-canvas/lib"; import { Server, Socket as RawSocket } from "socket.io"; import { session } from "./Express"; import Canvas from "./Canvas"; -import { PalleteColor } from "@prisma/client"; +import { PaletteColor } from "@prisma/client"; import { prisma } from "./prisma"; import { Logger } from "./Logger"; import { Redis } from "./redis"; @@ -40,14 +40,14 @@ const getSocketConfig = () => { }; // this is terrible, another way to get the client config needs to be found -let PALLETE: PalleteColor[] = []; +let PALLETE: PaletteColor[] = []; const PIXEL_TIMEOUT_MS = 1000; -prisma.palleteColor +prisma.paletteColor .findMany() - .then((palleteColors) => { - PALLETE = palleteColors; - Logger.info(`Loaded ${palleteColors.length} pallete colors`); + .then((paletteColors) => { + PALLETE = paletteColors; + Logger.info(`Loaded ${paletteColors.length} pallete colors`); }) .catch((e) => { Logger.error("Failed to get pallete colors", e); @@ -188,7 +188,7 @@ export class SocketServer { await user.modifyStack(-1); - const paletteColor = await prisma.palleteColor.findFirst({ + const paletteColor = await prisma.paletteColor.findFirst({ where: { id: pixel.color, },