diff --git a/prisma/migrations/20221019153247_cooldowns/migration.sql b/prisma/migrations/20221019153247_cooldowns/migration.sql new file mode 100644 index 0000000..ddaf6d9 --- /dev/null +++ b/prisma/migrations/20221019153247_cooldowns/migration.sql @@ -0,0 +1,12 @@ +-- CreateTable +CREATE TABLE "Cooldown" ( + "guildId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "cooldown" INTEGER NOT NULL, + "timeoutId" TEXT NOT NULL, + CONSTRAINT "Cooldown_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "Cooldown_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "Cooldown_guildId_userId_timeoutId_key" ON "Cooldown"("guildId", "userId", "timeoutId"); diff --git a/prisma/migrations/20221019153652_audit_dates/migration.sql b/prisma/migrations/20221019153652_audit_dates/migration.sql new file mode 100644 index 0000000..7bc464b --- /dev/null +++ b/prisma/migrations/20221019153652_audit_dates/migration.sql @@ -0,0 +1,86 @@ +/* + Warnings: + + - Added the required column `updatedAt` to the `Guild` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `Cooldown` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `GuildCounter` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `User` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `GuildMember` table without a default value. This is not possible if the table is not empty. + +*/ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Guild" ( + "id" TEXT NOT NULL, + "creditsEnabled" BOOLEAN NOT NULL DEFAULT false, + "creditsRate" INTEGER NOT NULL DEFAULT 1, + "creditsTimeout" INTEGER NOT NULL DEFAULT 5, + "creditsWorkRate" INTEGER NOT NULL DEFAULT 25, + "creditsWorkTimeout" INTEGER NOT NULL DEFAULT 86400, + "creditsMinimumLength" INTEGER NOT NULL DEFAULT 5, + "pointsEnabled" BOOLEAN NOT NULL DEFAULT false, + "pointsRate" INTEGER NOT NULL DEFAULT 1, + "pointsTimeout" INTEGER NOT NULL DEFAULT 5, + "pointsMinimumLength" INTEGER NOT NULL DEFAULT 5, + "reputationsEnabled" BOOLEAN NOT NULL DEFAULT false, + "countersEnabled" BOOLEAN NOT NULL DEFAULT false, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); +INSERT INTO "new_Guild" ("countersEnabled", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled") SELECT "countersEnabled", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled" FROM "Guild"; +DROP TABLE "Guild"; +ALTER TABLE "new_Guild" RENAME TO "Guild"; +CREATE UNIQUE INDEX "Guild_id_key" ON "Guild"("id"); +CREATE TABLE "new_Cooldown" ( + "guildId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "cooldown" INTEGER NOT NULL, + "timeoutId" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "Cooldown_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "Cooldown_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_Cooldown" ("cooldown", "guildId", "timeoutId", "userId") SELECT "cooldown", "guildId", "timeoutId", "userId" FROM "Cooldown"; +DROP TABLE "Cooldown"; +ALTER TABLE "new_Cooldown" RENAME TO "Cooldown"; +CREATE UNIQUE INDEX "Cooldown_guildId_userId_timeoutId_key" ON "Cooldown"("guildId", "userId", "timeoutId"); +CREATE TABLE "new_GuildCounter" ( + "guildId" TEXT NOT NULL, + "channelId" TEXT NOT NULL, + "triggerWord" TEXT NOT NULL, + "count" INTEGER NOT NULL DEFAULT 0, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildCounter_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildCounter" ("channelId", "count", "guildId", "triggerWord") SELECT "channelId", "count", "guildId", "triggerWord" FROM "GuildCounter"; +DROP TABLE "GuildCounter"; +ALTER TABLE "new_GuildCounter" RENAME TO "GuildCounter"; +CREATE UNIQUE INDEX "GuildCounter_guildId_channelId_key" ON "GuildCounter"("guildId", "channelId"); +CREATE TABLE "new_User" ( + "id" TEXT NOT NULL, + "reputationsEarned" INTEGER NOT NULL DEFAULT 0, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); +INSERT INTO "new_User" ("id", "reputationsEarned") SELECT "id", "reputationsEarned" FROM "User"; +DROP TABLE "User"; +ALTER TABLE "new_User" RENAME TO "User"; +CREATE UNIQUE INDEX "User_id_key" ON "User"("id"); +CREATE TABLE "new_GuildMember" ( + "userId" TEXT NOT NULL, + "guildId" TEXT NOT NULL, + "creditsEarned" INTEGER NOT NULL DEFAULT 0, + "pointsEarned" INTEGER NOT NULL DEFAULT 0, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildMember_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildMember" ("creditsEarned", "guildId", "pointsEarned", "userId") SELECT "creditsEarned", "guildId", "pointsEarned", "userId" FROM "GuildMember"; +DROP TABLE "GuildMember"; +ALTER TABLE "new_GuildMember" RENAME TO "GuildMember"; +CREATE UNIQUE INDEX "GuildMember_userId_guildId_key" ON "GuildMember"("userId", "guildId"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221019172846_embedconfig/migration.sql b/prisma/migrations/20221019172846_embedconfig/migration.sql new file mode 100644 index 0000000..f2d2415 --- /dev/null +++ b/prisma/migrations/20221019172846_embedconfig/migration.sql @@ -0,0 +1,30 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Guild" ( + "id" TEXT NOT NULL, + "embedColorSuccess" TEXT NOT NULL DEFAULT '#22bb33', + "embedColorWait" TEXT NOT NULL DEFAULT '#f0ad4e', + "embedColorError" TEXT NOT NULL DEFAULT '#bb2124', + "embedFooterText" TEXT NOT NULL DEFAULT 'https://github.com/ZynerOrg/xyter', + "embedFooterIcon" TEXT NOT NULL DEFAULT 'https://github.com/ZynerOrg.png', + "creditsEnabled" BOOLEAN NOT NULL DEFAULT false, + "creditsRate" INTEGER NOT NULL DEFAULT 1, + "creditsTimeout" INTEGER NOT NULL DEFAULT 5, + "creditsWorkRate" INTEGER NOT NULL DEFAULT 25, + "creditsWorkTimeout" INTEGER NOT NULL DEFAULT 86400, + "creditsMinimumLength" INTEGER NOT NULL DEFAULT 5, + "pointsEnabled" BOOLEAN NOT NULL DEFAULT false, + "pointsRate" INTEGER NOT NULL DEFAULT 1, + "pointsTimeout" INTEGER NOT NULL DEFAULT 5, + "pointsMinimumLength" INTEGER NOT NULL DEFAULT 5, + "reputationsEnabled" BOOLEAN NOT NULL DEFAULT false, + "countersEnabled" BOOLEAN NOT NULL DEFAULT false, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); +INSERT INTO "new_Guild" ("countersEnabled", "createdAt", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled", "updatedAt") SELECT "countersEnabled", "createdAt", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled", "updatedAt" FROM "Guild"; +DROP TABLE "Guild"; +ALTER TABLE "new_Guild" RENAME TO "Guild"; +CREATE UNIQUE INDEX "Guild_id_key" ON "Guild"("id"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7b621c1..0c19c74 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -12,10 +12,16 @@ datasource db { } model Guild { - id String @unique - GuildMember GuildMember[] + id String @unique + guildMembers GuildMember[] + cooldowns Cooldown[] // Settings + embedColorSuccess String @default("#22bb33") + embedColorWait String @default("#f0ad4e") + embedColorError String @default("#bb2124") + embedFooterText String @default("https://github.com/ZynerOrg/xyter") + embedFooterIcon String @default("https://github.com/ZynerOrg.png") // { // url: { @@ -65,6 +71,9 @@ model Guild { countersEnabled Boolean @default(false) counters GuildCounter[] + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt } model User { @@ -74,7 +83,11 @@ model User { // Settings // Modules - reputationsEarned Int @default(0) + reputationsEarned Int @default(0) + Cooldown Cooldown[] + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt } model GuildMember { @@ -90,6 +103,9 @@ model GuildMember { creditsEarned Int @default(0) pointsEarned Int @default(0) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + // Unique Identifier @@unique([userId, guildId]) } @@ -101,5 +117,22 @@ model GuildCounter { count Int @default(0) guild Guild @relation(fields: [guildId], references: [id]) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + @@unique([guildId, channelId]) } + +model Cooldown { + guild Guild @relation(fields: [guildId], references: [id]) + user User @relation(fields: [userId], references: [id]) + guildId String + userId String + cooldown Int + timeoutId String + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + @@unique([guildId, userId, timeoutId]) +}