diff --git a/prisma/migrations/20240412030727_refactorIds/migration.sql b/prisma/migrations/20240412030727_refactorIds/migration.sql new file mode 100644 index 0000000..75d2aef --- /dev/null +++ b/prisma/migrations/20240412030727_refactorIds/migration.sql @@ -0,0 +1,33 @@ +/* + Warnings: + + - The primary key for the `CommandStatistics` table will be changed. If it partially fails, the table could be left without primary key constraint. + - The `id` column on the `CommandStatistics` table would be dropped and recreated. This will lead to data loss if there is data in the column. + - The primary key for the `EmbedField` table will be changed. If it partially fails, the table could be left without primary key constraint. + - The `id` column on the `EmbedField` table would be dropped and recreated. This will lead to data loss if there is data in the column. + - You are about to drop the column `guildId` on the `Guild` table. All the data in the column will be lost. +*/ + +-- DropIndex +DROP INDEX "Guild_guildId_key"; + +-- AlterTable +ALTER TABLE "CommandStatistics" DROP CONSTRAINT "CommandStatistics_pkey", +DROP COLUMN "id", +ADD COLUMN "id" SERIAL NOT NULL, +ADD CONSTRAINT "CommandStatistics_pkey" PRIMARY KEY ("id"); + +-- AlterTable +ALTER TABLE "EmbedField" DROP CONSTRAINT "EmbedField_pkey", +DROP COLUMN "id", +ADD COLUMN "id" SERIAL NOT NULL, +ADD CONSTRAINT "EmbedField_pkey" PRIMARY KEY ("id"); + +-- AlterTable +ALTER TABLE "Guild" DROP COLUMN "guildId"; + +-- CreateIndex +CREATE UNIQUE INDEX "CommandStatistics_id_key" ON "CommandStatistics"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "EmbedField_id_key" ON "EmbedField"("id"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9374383..63784ba 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -12,12 +12,12 @@ datasource db { } model User { - id String @id @unique + id String @id @unique members Member[] } model Member { - id String @id @unique + id String @id @unique @default(cuid()) userId String user User @relation(fields: [userId], references: [id]) guildId String @@ -25,9 +25,8 @@ model Member { } model Guild { - id String @id @unique - guildId String @unique - Members Member[] + id String @id @unique + Members Member[] adminRoleId String? adminLogChannelId String? @@ -46,7 +45,7 @@ model Guild { } model CommandCooldown { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) cooldownId String @unique duration Int usages DateTime[] @@ -55,7 +54,7 @@ model CommandCooldown { // Configurable Messages for users // Check out the join/leave feed for an example model Embed { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) messageText String? color Int? authorName String? @@ -75,7 +74,7 @@ model Embed { } model EmbedField { - id String @id @unique + id Int @id @unique @default(autoincrement()) name String value String inline Boolean @@ -84,7 +83,7 @@ model EmbedField { } model CommandStatistics { - id String @id @unique + id Int @id @unique @default(autoincrement()) type Int commandId String @unique diff --git a/src/chat-input/Administrator/embeds/controllers.ts b/src/chat-input/Administrator/embeds/controllers.ts index 3a39375..69c1aa7 100644 --- a/src/chat-input/Administrator/embeds/controllers.ts +++ b/src/chat-input/Administrator/embeds/controllers.ts @@ -216,9 +216,9 @@ export const configureEmbedController: EmbedController = async ( ? resolveColor(`#${configureEmbedData.color.replaceAll('#', '')}`) : null; const createEmbedData: Prisma.EmbedCreateInput = { - memberJoinEmbed: { + [settingKey]: { connect: { - guildId: interaction.guildId, + id: guildSettings.id, }, }, messageText: configureEmbedMessage ?? null, @@ -241,7 +241,7 @@ export const configureEmbedController: EmbedController = async ( update: upsertData, create: createEmbedData, where: { - id: upsertId!, + id: upsertId, }, include: { fields: true }, }); diff --git a/src/database/Guilds.ts b/src/database/Guilds.ts index f9024d9..b0104ee 100644 --- a/src/database/Guilds.ts +++ b/src/database/Guilds.ts @@ -18,7 +18,7 @@ export type GuildWithEmbeds = Prisma.GuildGetPayload<{ export const guildSettingsFromDb = async (guildId: string): Promise => { const guild = await prisma.guild.findUnique({ - where: { guildId: guildId }, + where: { id: guildId }, include: { memberJoinEmbed: { include: { fields: true }, @@ -31,7 +31,7 @@ export const guildSettingsFromDb = async (guildId: string): Promise