fix: 🗃️ Perform migrations from older versions
This is my first customized migration script, I hope it works as intended. This may result in a database loss, please perform backups before proceeding, it should do migrate if everything works as intended
This commit is contained in:
parent
258e15c45d
commit
109b89c820
17 changed files with 337 additions and 171 deletions
|
@ -1,16 +0,0 @@
|
|||
-- AlterTable
|
||||
|
||||
ALTER TABLE `GuildMemberCredits` ADD COLUMN `balance` INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildMemberCredits (balance, userId, guildId)
|
||||
SELECT creditsEarned,
|
||||
userId,
|
||||
guildId
|
||||
FROM GuildMember;
|
||||
|
||||
-- DropColumn
|
||||
|
||||
ALTER TABLE GuildMember
|
||||
DROP COLUMN creditsEarned;
|
|
@ -1,77 +1,3 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `apiCpggTokenContent` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `apiCpggTokenIv` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `apiCpggUrlContent` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `apiCpggUrlIv` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `auditsChannelId` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `auditsEnabled` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `countersEnabled` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `creditsEnabled` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `creditsMinimumLength` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `creditsRate` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `creditsTimeout` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `creditsWorkRate` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `creditsWorkTimeout` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `embedColorError` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `embedColorSuccess` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `embedColorWait` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `embedFooterIcon` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `embedFooterText` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `pointsEnabled` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `pointsMinimumLength` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `pointsRate` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `pointsTimeout` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `reputationsEnabled` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `shopRolesEnabled` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `shopRolesPricePerHour` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `welcomeEnabled` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `welcomeJoinChannelId` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `welcomeJoinChannelMessage` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `welcomeLeaveChannelId` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `welcomeLeaveChannelMessage` on the `Guild` table. All the data in the column will be lost.
|
||||
- You are about to drop the `GuildCounter` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `GuildCounter` DROP FOREIGN KEY `GuildCounter_guildId_fkey`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Guild` DROP COLUMN `apiCpggTokenContent`,
|
||||
DROP COLUMN `apiCpggTokenIv`,
|
||||
DROP COLUMN `apiCpggUrlContent`,
|
||||
DROP COLUMN `apiCpggUrlIv`,
|
||||
DROP COLUMN `auditsChannelId`,
|
||||
DROP COLUMN `auditsEnabled`,
|
||||
DROP COLUMN `countersEnabled`,
|
||||
DROP COLUMN `creditsEnabled`,
|
||||
DROP COLUMN `creditsMinimumLength`,
|
||||
DROP COLUMN `creditsRate`,
|
||||
DROP COLUMN `creditsTimeout`,
|
||||
DROP COLUMN `creditsWorkRate`,
|
||||
DROP COLUMN `creditsWorkTimeout`,
|
||||
DROP COLUMN `embedColorError`,
|
||||
DROP COLUMN `embedColorSuccess`,
|
||||
DROP COLUMN `embedColorWait`,
|
||||
DROP COLUMN `embedFooterIcon`,
|
||||
DROP COLUMN `embedFooterText`,
|
||||
DROP COLUMN `pointsEnabled`,
|
||||
DROP COLUMN `pointsMinimumLength`,
|
||||
DROP COLUMN `pointsRate`,
|
||||
DROP COLUMN `pointsTimeout`,
|
||||
DROP COLUMN `reputationsEnabled`,
|
||||
DROP COLUMN `shopRolesEnabled`,
|
||||
DROP COLUMN `shopRolesPricePerHour`,
|
||||
DROP COLUMN `welcomeEnabled`,
|
||||
DROP COLUMN `welcomeJoinChannelId`,
|
||||
DROP COLUMN `welcomeJoinChannelMessage`,
|
||||
DROP COLUMN `welcomeLeaveChannelId`,
|
||||
DROP COLUMN `welcomeLeaveChannelMessage`;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `GuildCounter`;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `GuildConfigEmbeds` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
|
@ -134,16 +60,6 @@ CREATE TABLE `GuildConfigCounters` (
|
|||
UNIQUE INDEX `GuildConfigCounters_id_key`(`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `GuildConfigApis` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
`guildConfigApisCpggId` VARCHAR(191) NULL,
|
||||
|
||||
UNIQUE INDEX `GuildConfigApis_id_key`(`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `GuildConfigApisCpgg` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
|
@ -195,7 +111,7 @@ CREATE TABLE `GuildConfigWelcome` (
|
|||
`id` VARCHAR(191) NOT NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
`statis` BOOLEAN NOT NULL DEFAULT false,
|
||||
`status` BOOLEAN NOT NULL DEFAULT false,
|
||||
`joinChannelId` VARCHAR(191) NULL,
|
||||
`joinChannelMessage` VARCHAR(191) NULL,
|
||||
`leaveChannelId` VARCHAR(191) NULL,
|
||||
|
@ -231,12 +147,6 @@ ALTER TABLE `GuildConfigReputation` ADD CONSTRAINT `GuildConfigReputation_id_fke
|
|||
-- AddForeignKey
|
||||
ALTER TABLE `GuildConfigCounters` ADD CONSTRAINT `GuildConfigCounters_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `GuildConfigApis` ADD CONSTRAINT `GuildConfigApis_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `GuildConfigApis` ADD CONSTRAINT `GuildConfigApis_guildConfigApisCpggId_fkey` FOREIGN KEY (`guildConfigApisCpggId`) REFERENCES `GuildConfigApisCpgg`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `GuildConfigApisCpgg` ADD CONSTRAINT `GuildConfigApisCpgg_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
|
@ -257,3 +167,283 @@ ALTER TABLE `GuildConfigWelcome` ADD CONSTRAINT `GuildConfigWelcome_id_fkey` FOR
|
|||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `GuildCounters` ADD CONSTRAINT `GuildCounters_guildId_fkey` FOREIGN KEY (`guildId`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `GuildMemberCredits` ADD COLUMN `balance` INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildConfigApisCpgg (tokenContent,tokenIv,urlContent,urlIv,id,updatedAt)
|
||||
SELECT apiCpggTokenContent,apiCpggTokenIv,apiCpggUrlContent,apiCpggUrlIv,id,updatedAt
|
||||
FROM Guild
|
||||
WHERE
|
||||
(
|
||||
apiCpggTokenContent IS NOT NULL
|
||||
AND
|
||||
apiCpggTokenIv IS NOT NULL
|
||||
AND
|
||||
apiCpggUrlContent IS NOT NULL
|
||||
AND
|
||||
apiCpggUrlIv IS NOT NULL
|
||||
AND
|
||||
id IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `Guild` DROP COLUMN `apiCpggTokenContent`,
|
||||
DROP COLUMN `apiCpggTokenIv`,
|
||||
DROP COLUMN `apiCpggUrlContent`,
|
||||
DROP COLUMN `apiCpggUrlIv`;
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildConfigAudits (status,channelId,id,updatedAt)
|
||||
SELECT auditsEnabled,auditsChannelId,id,updatedAt
|
||||
FROM Guild
|
||||
WHERE
|
||||
(
|
||||
auditsEnabled IS NOT NULL
|
||||
AND
|
||||
auditsChannelId IS NOT NULL
|
||||
AND
|
||||
id IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `Guild` DROP COLUMN `auditsChannelId`,
|
||||
DROP COLUMN `auditsEnabled`;
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildConfigCounters (status,id,updatedAt)
|
||||
SELECT countersEnabled,id,updatedAt
|
||||
FROM Guild
|
||||
WHERE
|
||||
(
|
||||
countersEnabled IS NOT NULL
|
||||
AND
|
||||
id IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `Guild` DROP COLUMN `countersEnabled`;
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildConfigCredits (status,minimumLength,rate,timeout,workRate,workTimeout,id,updatedAt)
|
||||
SELECT creditsEnabled,creditsMinimumLength,creditsRate,creditsTimeout,creditsWorkRate,creditsWorkTimeout,id,updatedAt
|
||||
FROM Guild
|
||||
WHERE
|
||||
(
|
||||
creditsEnabled IS NOT NULL
|
||||
AND
|
||||
creditsMinimumLength IS NOT NULL
|
||||
AND
|
||||
creditsRate IS NOT NULL
|
||||
AND
|
||||
creditsTimeout IS NOT NULL
|
||||
AND
|
||||
creditsWorkRate IS NOT NULL
|
||||
AND
|
||||
creditsWorkTimeout IS NOT NULL
|
||||
AND
|
||||
id IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `Guild` DROP COLUMN `creditsEnabled`,
|
||||
DROP COLUMN `creditsMinimumLength`,
|
||||
DROP COLUMN `creditsRate`,
|
||||
DROP COLUMN `creditsTimeout`,
|
||||
DROP COLUMN `creditsWorkRate`,
|
||||
DROP COLUMN `creditsWorkTimeout`;
|
||||
|
||||
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildConfigEmbeds (errorColor,successColor,waitColor,footerIcon,footerText,id,updatedAt)
|
||||
SELECT embedColorError,embedColorSuccess,embedColorWait,embedFooterIcon,embedFooterText,id,updatedAt
|
||||
FROM Guild
|
||||
WHERE
|
||||
(
|
||||
embedColorError IS NOT NULL
|
||||
AND
|
||||
embedColorSuccess IS NOT NULL
|
||||
AND
|
||||
embedColorWait IS NOT NULL
|
||||
AND
|
||||
embedFooterIcon IS NOT NULL
|
||||
AND
|
||||
embedFooterText IS NOT NULL
|
||||
AND
|
||||
id IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `Guild` DROP COLUMN `embedColorError`,
|
||||
DROP COLUMN `embedColorSuccess`,
|
||||
DROP COLUMN `embedColorWait`,
|
||||
DROP COLUMN `embedFooterIcon`,
|
||||
DROP COLUMN `embedFooterText`;
|
||||
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildConfigPoints (status,minimumLength,rate,timeout,id,updatedAt)
|
||||
SELECT pointsEnabled,pointsMinimumLength,pointsRate,pointsTimeout,id,updatedAt
|
||||
FROM Guild
|
||||
WHERE
|
||||
(
|
||||
pointsEnabled IS NOT NULL
|
||||
AND
|
||||
pointsMinimumLength IS NOT NULL
|
||||
AND
|
||||
pointsRate IS NOT NULL
|
||||
AND
|
||||
pointsTimeout IS NOT NULL
|
||||
AND
|
||||
id IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `Guild` DROP COLUMN `pointsEnabled`,
|
||||
DROP COLUMN `pointsMinimumLength`,
|
||||
DROP COLUMN `pointsRate`,
|
||||
DROP COLUMN `pointsTimeout`;
|
||||
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildConfigReputation (status,id,updatedAt)
|
||||
SELECT reputationsEnabled,id,updatedAt
|
||||
FROM Guild
|
||||
WHERE
|
||||
(
|
||||
reputationsEnabled IS NOT NULL
|
||||
AND
|
||||
id IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `Guild` DROP COLUMN `reputationsEnabled`;
|
||||
|
||||
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildConfigShopRoles (status,pricePerHour,id,updatedAt)
|
||||
SELECT shopRolesEnabled,shopRolesPricePerHour,id,updatedAt
|
||||
FROM Guild
|
||||
WHERE
|
||||
(
|
||||
shopRolesEnabled IS NOT NULL
|
||||
AND
|
||||
shopRolesPricePerHour IS NOT NULL
|
||||
AND
|
||||
id IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `Guild` DROP COLUMN `shopRolesEnabled`,
|
||||
DROP COLUMN `shopRolesPricePerHour`;
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildConfigWelcome (status,joinChannelId,joinChannelMessage,leaveChannelId,leaveChannelMessage,id,updatedAt)
|
||||
SELECT welcomeEnabled,welcomeJoinChannelId,welcomeJoinChannelMessage,welcomeLeaveChannelId,welcomeLeaveChannelMessage,id,updatedAt
|
||||
FROM Guild
|
||||
WHERE
|
||||
(
|
||||
welcomeEnabled IS NOT NULL
|
||||
AND
|
||||
welcomeJoinChannelId IS NOT NULL
|
||||
AND
|
||||
welcomeJoinChannelMessage IS NOT NULL
|
||||
AND
|
||||
welcomeLeaveChannelId IS NOT NULL
|
||||
AND
|
||||
id IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Guild` DROP COLUMN `welcomeEnabled`,
|
||||
DROP COLUMN `welcomeJoinChannelId`,
|
||||
DROP COLUMN `welcomeJoinChannelMessage`,
|
||||
DROP COLUMN `welcomeLeaveChannelId`,
|
||||
DROP COLUMN `welcomeLeaveChannelMessage`;
|
||||
|
||||
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildCounters (guildId,channelId,triggerWord,count,updatedAt)
|
||||
SELECT guildId,channelId,triggerWord,count,updatedAt
|
||||
FROM GuildCounter
|
||||
WHERE
|
||||
(
|
||||
guildId IS NOT NULL
|
||||
AND
|
||||
channelId IS NOT NULL
|
||||
AND
|
||||
triggerWord IS NOT NULL
|
||||
AND
|
||||
count IS NOT NULL
|
||||
AND
|
||||
updatedAt IS NOT NULL
|
||||
);
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `GuildCounter`;
|
||||
|
||||
-- InsertInto
|
||||
|
||||
INSERT INTO GuildMemberCredits (balance,userId,guildId)
|
||||
SELECT creditsEarned,userid,guildId
|
||||
FROM GuildMember
|
||||
WHERE
|
||||
(
|
||||
creditsEarned IS NOT NULL
|
||||
AND
|
||||
userId IS NOT NULL
|
||||
AND
|
||||
guildId IS NOT NULL
|
||||
);
|
||||
|
||||
-- DeleteFrom
|
||||
DELETE FROM GuildMemberCredits
|
||||
WHERE balance = 0;
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE `GuildMember` DROP COLUMN `creditsEarned`;
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `statis` on the `GuildConfigWelcome` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `GuildConfigWelcome` DROP COLUMN `statis`,
|
||||
ADD COLUMN `status` BOOLEAN NOT NULL DEFAULT false;
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `GuildConfigApis` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `GuildConfigApis` DROP FOREIGN KEY `GuildConfigApis_guildConfigApisCpggId_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `GuildConfigApis` DROP FOREIGN KEY `GuildConfigApis_id_fkey`;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `GuildConfigApis`;
|
|
@ -49,12 +49,12 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||
id: guild.id,
|
||||
},
|
||||
update: {
|
||||
status: status,
|
||||
status,
|
||||
channelId: channel.id,
|
||||
},
|
||||
create: {
|
||||
id: guild.id,
|
||||
status: status,
|
||||
status,
|
||||
channelId: channel.id,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -95,20 +95,20 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||
},
|
||||
update: {
|
||||
status: enabled,
|
||||
rate: rate,
|
||||
timeout: timeout,
|
||||
workRate: workRate,
|
||||
workTimeout: workTimeout,
|
||||
minimumLength: minimumLength,
|
||||
rate,
|
||||
timeout,
|
||||
workRate,
|
||||
workTimeout,
|
||||
minimumLength,
|
||||
},
|
||||
create: {
|
||||
id: guild.id,
|
||||
status: enabled,
|
||||
rate: rate,
|
||||
timeout: timeout,
|
||||
workRate: workRate,
|
||||
workTimeout: workTimeout,
|
||||
minimumLength: minimumLength,
|
||||
rate,
|
||||
timeout,
|
||||
workRate,
|
||||
workTimeout,
|
||||
minimumLength,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -67,17 +67,17 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||
id: guild.id,
|
||||
},
|
||||
update: {
|
||||
status: status,
|
||||
rate: rate,
|
||||
timeout: timeout,
|
||||
minimumLength: minimumLength,
|
||||
status,
|
||||
rate,
|
||||
timeout,
|
||||
minimumLength,
|
||||
},
|
||||
create: {
|
||||
id: guild.id,
|
||||
status: status,
|
||||
rate: rate,
|
||||
timeout: timeout,
|
||||
minimumLength: minimumLength,
|
||||
status,
|
||||
rate,
|
||||
timeout,
|
||||
minimumLength,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -81,19 +81,19 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||
id: guild.id,
|
||||
},
|
||||
update: {
|
||||
status: status,
|
||||
status,
|
||||
joinChannelId: joinChannel.id,
|
||||
joinChannelMessage: joinChannelMessage,
|
||||
joinChannelMessage,
|
||||
leaveChannelId: leaveChannel.id,
|
||||
leaveChannelMessage: leaveChannelMessage,
|
||||
leaveChannelMessage,
|
||||
},
|
||||
create: {
|
||||
id: guild.id,
|
||||
status: status,
|
||||
status,
|
||||
joinChannelId: joinChannel.id,
|
||||
joinChannelMessage: joinChannelMessage,
|
||||
joinChannelMessage,
|
||||
leaveChannelId: leaveChannel.id,
|
||||
leaveChannelMessage: leaveChannelMessage,
|
||||
leaveChannelMessage,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { CommandInteraction, SlashCommandSubcommandBuilder } from "discord.js";
|
|||
import prisma from "../../../../handlers/database";
|
||||
import deferReply from "../../../../handlers/deferReply";
|
||||
import { success as BaseEmbedSuccess } from "../../../../helpers/baseEmbeds";
|
||||
import upsertGuildMember from "../../../../helpers/upsertGuildMember";
|
||||
import logger from "../../../../middlewares/logger";
|
||||
|
||||
// 1. Export a builder function.
|
||||
|
@ -33,7 +34,7 @@ export const execute = async (interaction: CommandInteraction) => {
|
|||
const EmbedSuccess = await BaseEmbedSuccess(guild, ":credit_card:︱Balance");
|
||||
|
||||
// 5. Upsert the user in the database.
|
||||
const createGuildMember = await prisma.guildMemberCredits.upsert({
|
||||
const createGuildMemberCredits = await prisma.guildMemberCredits.upsert({
|
||||
where: {
|
||||
userId_guildId: {
|
||||
userId: (target || user).id,
|
||||
|
@ -60,15 +61,17 @@ export const execute = async (interaction: CommandInteraction) => {
|
|||
include: { GuildMember: true },
|
||||
});
|
||||
|
||||
logger.silly(createGuildMember);
|
||||
logger.silly(createGuildMemberCredits);
|
||||
|
||||
await upsertGuildMember(guild, user);
|
||||
|
||||
// 6. Send embed.
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
EmbedSuccess.setDescription(
|
||||
target
|
||||
? `${target} has ${createGuildMember.balance} coins in his account.`
|
||||
: `You have ${createGuildMember.balance} coins in your account.`
|
||||
? `${target} has ${createGuildMemberCredits.balance} coins in his account.`
|
||||
: `You have ${createGuildMemberCredits.balance} coins in your account.`
|
||||
),
|
||||
],
|
||||
});
|
||||
|
|
|
@ -7,6 +7,7 @@ import prisma from "../../../../handlers/database";
|
|||
import deferReply from "../../../../handlers/deferReply";
|
||||
import { success as BaseEmbedSuccess } from "../../../../helpers/baseEmbeds";
|
||||
import creditsTransfer from "../../../../helpers/credits/transfer";
|
||||
import upsertGuildMember from "../../../../helpers/upsertGuildMember";
|
||||
import logger from "../../../../middlewares/logger";
|
||||
|
||||
// 1. Export a builder function.
|
||||
|
@ -59,6 +60,8 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||
`:credit_card:︱You received a gift from ${user.username}`
|
||||
);
|
||||
|
||||
await upsertGuildMember(guild, user);
|
||||
|
||||
// 5. Start an transaction of the credits.
|
||||
await creditsTransfer(guild, user, account, credits);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
import prisma from "../../../../handlers/database";
|
||||
import deferReply from "../../../../handlers/deferReply";
|
||||
import { success as BaseEmbedSuccess } from "../../../../helpers/baseEmbeds";
|
||||
import upsertGuildMember from "../../../../helpers/upsertGuildMember";
|
||||
import logger from "../../../../middlewares/logger";
|
||||
|
||||
// 1. Export a builder function.
|
||||
|
@ -21,10 +22,12 @@ export const execute = async (interaction: CommandInteraction) => {
|
|||
await deferReply(interaction, false);
|
||||
|
||||
// 2. Destructure interaction object.
|
||||
const { guild, client } = interaction;
|
||||
const { guild, client, user } = interaction;
|
||||
if (!guild) throw new Error("Guild not found");
|
||||
if (!client) throw new Error("Client not found");
|
||||
|
||||
await upsertGuildMember(guild, user);
|
||||
|
||||
// 3. Create base embeds.
|
||||
const EmbedSuccess = await BaseEmbedSuccess(guild, "[:dollar:] Top");
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import prisma from "../../../../handlers/database";
|
|||
import deferReply from "../../../../handlers/deferReply";
|
||||
import { success as BaseEmbedSuccess } from "../../../../helpers/baseEmbeds";
|
||||
import creditsGive from "../../../../helpers/credits/give";
|
||||
import upsertGuildMember from "../../../../helpers/upsertGuildMember";
|
||||
import cooldown from "../../../../middlewares/cooldown";
|
||||
import logger from "../../../../middlewares/logger";
|
||||
|
||||
|
@ -23,6 +24,8 @@ export const execute = async (interaction: CommandInteraction) => {
|
|||
if (!guild) throw new Error("Guild not found");
|
||||
if (!user) throw new Error("User not found");
|
||||
|
||||
await upsertGuildMember(guild, user);
|
||||
|
||||
// 3. Create base embeds.
|
||||
const EmbedSuccess = await BaseEmbedSuccess(guild, "[:dollar:] Work");
|
||||
|
||||
|
@ -51,13 +54,13 @@ export const execute = async (interaction: CommandInteraction) => {
|
|||
max: createGuild.workRate,
|
||||
});
|
||||
|
||||
const upsertGuildMember = await creditsGive(guild, user, creditsEarned);
|
||||
const upsertGuildMemberResult = await creditsGive(guild, user, creditsEarned);
|
||||
|
||||
// 8. Send embed.
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
EmbedSuccess.setDescription(
|
||||
`You worked and earned **${creditsEarned}** credits! You now have **${upsertGuildMember.balance}** credits. :tada:`
|
||||
`You worked and earned **${creditsEarned}** credits! You now have **${upsertGuildMemberResult.balance}** credits. :tada:`
|
||||
),
|
||||
],
|
||||
});
|
||||
|
|
|
@ -53,7 +53,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
); // Destructure
|
||||
const { guild, user, options } = interaction;
|
||||
const { guild, options } = interaction;
|
||||
|
||||
const uses = options?.getInteger("uses");
|
||||
const creditAmount = options?.getInteger("credit");
|
||||
|
|
|
@ -13,7 +13,10 @@ export default {
|
|||
where: { id: member.guild.id },
|
||||
});
|
||||
|
||||
if (!getGuildConfigWelcome) return logger.verbose("Guild not found");
|
||||
if (!getGuildConfigWelcome) {
|
||||
logger.verbose("Guild not found");
|
||||
return;
|
||||
}
|
||||
|
||||
const { client } = member;
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ export const execute = async (message: Message) => {
|
|||
await modules.points.execute(message);
|
||||
await modules.counters.execute(message);
|
||||
|
||||
const { client } = message;
|
||||
if (!message.member) return;
|
||||
if (message.author.bot) return;
|
||||
|
||||
|
|
|
@ -7,7 +7,10 @@ export default async (guild: Guild, embed: EmbedBuilder) => {
|
|||
const getGuildConfigAudits = await prisma.guildConfigAudits.findUnique({
|
||||
where: { id: guild.id },
|
||||
});
|
||||
if (!getGuildConfigAudits) return logger.verbose("Guild not found");
|
||||
if (!getGuildConfigAudits) {
|
||||
logger.verbose("Guild not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (getGuildConfigAudits.status !== true) return;
|
||||
if (!getGuildConfigAudits.channelId) {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import { GuildMember } from "discord.js";
|
||||
import { Guild, User } from "discord.js";
|
||||
import db from "../../handlers/database";
|
||||
|
||||
export default async (guildMember: GuildMember) => {
|
||||
const { guild, user } = guildMember;
|
||||
|
||||
export default async (guild: Guild, user: User) => {
|
||||
return await db.guildMember.upsert({
|
||||
where: {
|
||||
userId_guildId: {
|
||||
|
|
Loading…
Add table
Reference in a new issue