diff --git a/prisma/migrations/20230618111706_add_member_model/migration.sql b/prisma/migrations/0_init/migration.sql similarity index 58% rename from prisma/migrations/20230618111706_add_member_model/migration.sql rename to prisma/migrations/0_init/migration.sql index e22ec0e..8886a04 100644 --- a/prisma/migrations/20230618111706_add_member_model/migration.sql +++ b/prisma/migrations/0_init/migration.sql @@ -9,9 +9,12 @@ CREATE TABLE "guild" ( -- CreateTable CREATE TABLE "member" ( - "id" TEXT NOT NULL, + "id" UUID NOT NULL DEFAULT gen_random_uuid(), "name" TEXT NOT NULL, - "booster_role_id" TEXT NOT NULL, + "booster_role_id" TEXT, + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "dgid" TEXT NOT NULL, + "duid" TEXT NOT NULL, CONSTRAINT "member_pkey" PRIMARY KEY ("id") ); @@ -20,7 +23,4 @@ CREATE TABLE "member" ( CREATE UNIQUE INDEX "guild_id_key" ON "guild"("id"); -- CreateIndex -CREATE UNIQUE INDEX "member_id_key" ON "member"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "member_booster_role_id_key" ON "member"("booster_role_id"); +CREATE UNIQUE INDEX "member_dgid_duid_key" ON "member"("dgid", "duid"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5e425e7..5463950 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,5 +1,6 @@ generator client { - provider = "prisma-client-js" + provider = "prisma-client-js" + previewFeatures = ["postgresqlExtensions"] } datasource db { @@ -14,7 +15,14 @@ model guild { } model member { - id String @id @unique + id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid name String - booster_role_id String @unique + booster_role_id String? + created_at DateTime @default(now()) + /// Discord Guild ID + dgid String + /// Discord User ID + duid String + + @@unique([dgid, duid]) } diff --git a/src/commands/admin.ts b/src/commands/admin.ts index 8e54a18..49cdfa4 100644 --- a/src/commands/admin.ts +++ b/src/commands/admin.ts @@ -6,14 +6,7 @@ import { PermissionsBitField, Role, } from "discord.js"; -import { - Discord, - Guard, - GuardFunction, - Slash, - SlashGroup, - SlashOption, -} from "discordx"; +import { Discord, Slash, SlashGroup, SlashOption } from "discordx"; import { prisma } from "../main.js"; @Discord() @@ -108,24 +101,28 @@ export class AdminCmds { ) { let mem = await prisma.member.findUnique({ where: { - id: member.id, + dgid_duid: { + duid: member.id, + dgid: member.guild.id, + }, }, }); if (mem) { await prisma.member.update({ where: { - id: member.id, + id: mem.id, }, data: { - name: mem.name != member.displayName ? member.displayName : undefined, booster_role_id: role.id, + name: member.displayName, }, }); } else { await prisma.member.create({ data: { - id: member.id, + duid: member.id, + dgid: interaction.guildId!, name: member.displayName, booster_role_id: role.id, }, diff --git a/tsconfig.json b/tsconfig.json index 646fe35..949e75a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, - + "noImplicitAny": false, "skipLibCheck": true, "forceConsistentCasingInFileNames": true },