feat: 🗃️ add createdAt & updatedAt fields for Cooldowns

Added timestamps for when a cooldown was created and last time updated
This commit is contained in:
Axel Olausson Holtenäs 2023-05-29 15:21:22 +02:00
parent 41af2032ac
commit 3cf88abfd0
5 changed files with 146 additions and 53 deletions

View file

@ -0,0 +1,105 @@
/*
Warnings:
- You are about to drop the column `minimumLength` on the `GuildCreditsSettings` table. All the data in the column will be lost.
- You are about to drop the column `rate` on the `GuildCreditsSettings` table. All the data in the column will be lost.
- You are about to drop the column `status` on the `GuildCreditsSettings` table. All the data in the column will be lost.
- You are about to drop the column `timeout` on the `GuildCreditsSettings` table. All the data in the column will be lost.
- You are about to drop the column `workRate` on the `GuildCreditsSettings` table. All the data in the column will be lost.
- You are about to drop the column `workTimeout` on the `GuildCreditsSettings` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE `ApiCredentials` DROP FOREIGN KEY `ApiCredentials_guildId_fkey`;
-- DropForeignKey
ALTER TABLE `ApiCredentials` DROP FOREIGN KEY `ApiCredentials_guildId_userId_fkey`;
-- DropForeignKey
ALTER TABLE `ApiCredentials` DROP FOREIGN KEY `ApiCredentials_userId_fkey`;
-- DropForeignKey
ALTER TABLE `Cooldown` DROP FOREIGN KEY `Cooldown_guildId_fkey`;
-- DropForeignKey
ALTER TABLE `Cooldown` DROP FOREIGN KEY `Cooldown_guildId_userId_fkey`;
-- DropForeignKey
ALTER TABLE `Cooldown` DROP FOREIGN KEY `Cooldown_userId_fkey`;
-- DropForeignKey
ALTER TABLE `GuildCreditsSettings` DROP FOREIGN KEY `GuildCreditsSettings_id_fkey`;
-- DropForeignKey
ALTER TABLE `GuildMember` DROP FOREIGN KEY `GuildMember_guildId_fkey`;
-- DropForeignKey
ALTER TABLE `GuildMember` DROP FOREIGN KEY `GuildMember_userId_fkey`;
-- DropForeignKey
ALTER TABLE `GuildMemberCredit` DROP FOREIGN KEY `GuildMemberCredit_guildId_userId_fkey`;
-- DropForeignKey
ALTER TABLE `GuildSettings` DROP FOREIGN KEY `GuildSettings_guildCreditsSettingsId_fkey`;
-- DropForeignKey
ALTER TABLE `GuildSettings` DROP FOREIGN KEY `GuildSettings_id_fkey`;
-- DropForeignKey
ALTER TABLE `UserReputation` DROP FOREIGN KEY `UserReputation_id_fkey`;
-- AlterTable
ALTER TABLE `GuildCreditsSettings` DROP COLUMN `minimumLength`,
DROP COLUMN `rate`,
DROP COLUMN `status`,
DROP COLUMN `timeout`,
DROP COLUMN `workRate`,
DROP COLUMN `workTimeout`;
-- CreateIndex
CREATE INDEX `GuildMemberCredit_guildId_idx` ON `GuildMemberCredit`(`guildId`);
-- CreateIndex
CREATE INDEX `GuildMemberCredit_userId_idx` ON `GuildMemberCredit`(`userId`);
-- CreateIndex
CREATE INDEX `GuildMemberCredit_guildId_userId_idx` ON `GuildMemberCredit`(`guildId`, `userId`);
-- AddForeignKey
ALTER TABLE `GuildMember` ADD CONSTRAINT `GuildMember_guildId_fkey` FOREIGN KEY (`guildId`) REFERENCES `Guild`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `GuildMember` ADD CONSTRAINT `GuildMember_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `GuildMemberCredit` ADD CONSTRAINT `GuildMemberCredit_guildId_userId_fkey` FOREIGN KEY (`guildId`, `userId`) REFERENCES `GuildMember`(`guildId`, `userId`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `UserReputation` ADD CONSTRAINT `UserReputation_id_fkey` FOREIGN KEY (`id`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `GuildSettings` ADD CONSTRAINT `GuildSettings_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `GuildSettings` ADD CONSTRAINT `GuildSettings_guildCreditsSettingsId_fkey` FOREIGN KEY (`guildCreditsSettingsId`) REFERENCES `GuildCreditsSettings`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `GuildCreditsSettings` ADD CONSTRAINT `GuildCreditsSettings_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `ApiCredentials` ADD CONSTRAINT `ApiCredentials_guildId_fkey` FOREIGN KEY (`guildId`) REFERENCES `Guild`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `ApiCredentials` ADD CONSTRAINT `ApiCredentials_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `ApiCredentials` ADD CONSTRAINT `ApiCredentials_guildId_userId_fkey` FOREIGN KEY (`guildId`, `userId`) REFERENCES `GuildMember`(`guildId`, `userId`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Cooldown` ADD CONSTRAINT `Cooldown_guildId_fkey` FOREIGN KEY (`guildId`) REFERENCES `Guild`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Cooldown` ADD CONSTRAINT `Cooldown_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Cooldown` ADD CONSTRAINT `Cooldown_guildId_userId_fkey` FOREIGN KEY (`guildId`, `userId`) REFERENCES `GuildMember`(`guildId`, `userId`) ON DELETE CASCADE ON UPDATE CASCADE;

View file

@ -0,0 +1,13 @@
/*
Warnings:
- The primary key for the `Cooldown` table will be changed. If it partially fails, the table could be left without primary key constraint.
- Added the required column `updatedAt` to the `Cooldown` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `Cooldown` DROP PRIMARY KEY,
ADD COLUMN `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
ADD COLUMN `updatedAt` DATETIME(3) NOT NULL,
MODIFY `id` VARCHAR(191) NOT NULL,
ADD PRIMARY KEY (`id`);

View file

@ -30,12 +30,14 @@ model User {
}
model GuildMember {
guildId String
userId String
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
guildId String
userId String
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
guildMemberCredit GuildMemberCredit?
apiCredentials ApiCredentials[]
cooldowns Cooldown[]
@ -53,6 +55,9 @@ model GuildMemberCredit {
balance Int @default(0)
@@unique([guildId, userId])
@@index([guildId])
@@index([userId])
@@index([guildId, userId])
}
model UserReputation {
@ -71,8 +76,10 @@ model GuildSettings {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
guild Guild @relation(fields: [id], references: [id], onDelete: Cascade)
creditsSettings GuildCreditsSettings? @relation(fields: [guildCreditsSettingsId], references: [id], onDelete: Cascade)
guild Guild @relation(fields: [id], references: [id], onDelete: Cascade)
creditsSettings GuildCreditsSettings? @relation(fields: [guildCreditsSettingsId], references: [id], onDelete: Cascade)
guildCreditsSettingsId String?
}
@ -92,12 +99,6 @@ model GuildCreditsSettings {
weeklyBonusAmount Int @default(50)
monthlyBonusAmount Int @default(150)
status Boolean @default(false)
rate Int @default(1)
timeout Int @default(5)
workRate Int @default(25)
workTimeout Int @default(86400)
minimumLength Int @default(5)
guildSettings GuildSettings[]
}
@ -122,14 +123,19 @@ model ApiCredentials {
}
model Cooldown {
id Int @id @default(autoincrement())
cooldownItem String
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
expiresAt DateTime
guild Guild? @relation(fields: [guildId], references: [id], onDelete: Cascade)
guildId String?
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String?
guildMember GuildMember? @relation(fields: [guildId, userId], references: [guildId, userId], onDelete: Cascade)
cooldownItem String
guild Guild? @relation(fields: [guildId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
guildMember GuildMember? @relation(fields: [guildId, userId], references: [guildId, userId], onDelete: Cascade)
guildId String?
userId String?
@@index([cooldownItem, guildId], name: "cooldownItem_guildId_idx")
@@index([cooldownItem, userId], name: "cooldownItem_userId_idx")

View file

@ -11,37 +11,6 @@ export const execute = async (guild: Guild) => {
const guildId = guild.id; // Assuming guild.id is the unique ID of the guild
try {
// Delete related models based on guildId
await prisma.guildMember.deleteMany({
where: {
guildId,
},
});
await prisma.apiCredentials.deleteMany({
where: {
guildId,
},
});
await prisma.guildCreditsSettings.deleteMany({
where: {
id: guildId,
},
});
await prisma.guildMemberCredit.deleteMany({
where: {
guildId,
},
});
await prisma.guildSettings.deleteMany({
where: {
id: guildId,
},
});
// Delete the Guild model
await prisma.guild.deleteMany({
where: {

View file

@ -47,7 +47,7 @@ function createButtons() {
);
}
function createCooldownEmbed(timeLeft: string, cooldownId: number) {
function createCooldownEmbed(timeLeft: string, cooldownId: string) {
return new EmbedBuilder()
.setAuthor({ name: "⚠️ | Request Failed" })
.setDescription(