From 2de5afd6487779f2b070893fcf76d8d42506255c Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 14 Nov 2023 17:46:12 +0100 Subject: [PATCH] Rebased & fixed backend #410 --- .../migration/scheduled_event_migration.py | 45 ------------------- .../scripts/1.2.2/1_ScheduledEvents_down.sql | 3 ++ .../1.2.2/1_ScheduledEvents_up.sql} | 40 ++++++++++++----- .../modules/achievements/achievements.json | 4 +- bot/src/modules/config/config.json | 4 +- .../short_role_name/short-role-name.json | 4 +- .../special_offers/special-offers.json | 4 +- .../migration_to_sql/migration-to-sql.json | 10 ++--- 8 files changed, 45 insertions(+), 69 deletions(-) delete mode 100644 bot/src/bot_data/migration/scheduled_event_migration.py create mode 100644 bot/src/bot_data/scripts/1.2.2/1_ScheduledEvents_down.sql rename bot/src/bot_data/{migration/db_history_scripts/scheduled_events.sql => scripts/1.2.2/1_ScheduledEvents_up.sql} (63%) diff --git a/bot/src/bot_data/migration/scheduled_event_migration.py b/bot/src/bot_data/migration/scheduled_event_migration.py deleted file mode 100644 index ee0dde63..00000000 --- a/bot/src/bot_data/migration/scheduled_event_migration.py +++ /dev/null @@ -1,45 +0,0 @@ -from bot_core.logging.database_logger import DatabaseLogger -from bot_data.abc.migration_abc import MigrationABC -from bot_data.db_context import DBContext - - -class ScheduledEventMigration(MigrationABC): - name = "1.2.0_ScheduledEventMigration" - - def __init__(self, logger: DatabaseLogger, db: DBContext): - MigrationABC.__init__(self) - self._logger = logger - self._db = db - self._cursor = db.cursor - - def upgrade(self): - self._logger.debug(__name__, "Running upgrade") - - self._cursor.execute( - str( - f""" - CREATE TABLE IF NOT EXISTS `ScheduledEvents` ( - `Id` BIGINT NOT NULL AUTO_INCREMENT, - `Interval` VARCHAR(255) NOT NULL, - `Name` VARCHAR(255) NOT NULL, - `Description` VARCHAR(255) NOT NULL, - `ChannelId` BIGINT NULL, - `StartTime` DATETIME(6) NOT NULL, - `EndTime` DATETIME(6) NULL, - `EntityType` ENUM('1','2','3') NOT NULL, - `Location` VARCHAR(255) NULL, - `ServerId` BIGINT, - `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6), - `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), - PRIMARY KEY(`Id`), - FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`) - ); - """ - ) - ) - - self._exec(__file__, "scheduled_events.sql") - - def downgrade(self): - self._cursor.execute("DROP TABLE `ShortRoleNames`;") - self._cursor.execute("DROP TABLE `ShortRoleNamesHistory`;") diff --git a/bot/src/bot_data/scripts/1.2.2/1_ScheduledEvents_down.sql b/bot/src/bot_data/scripts/1.2.2/1_ScheduledEvents_down.sql new file mode 100644 index 00000000..d055ec13 --- /dev/null +++ b/bot/src/bot_data/scripts/1.2.2/1_ScheduledEvents_down.sql @@ -0,0 +1,3 @@ +DROP TABLE `ShortRoleNames`; + +DROP TABLE `ShortRoleNamesHistory`; \ No newline at end of file diff --git a/bot/src/bot_data/migration/db_history_scripts/scheduled_events.sql b/bot/src/bot_data/scripts/1.2.2/1_ScheduledEvents_up.sql similarity index 63% rename from bot/src/bot_data/migration/db_history_scripts/scheduled_events.sql rename to bot/src/bot_data/scripts/1.2.2/1_ScheduledEvents_up.sql index d456b410..2768651e 100644 --- a/bot/src/bot_data/migration/db_history_scripts/scheduled_events.sql +++ b/bot/src/bot_data/scripts/1.2.2/1_ScheduledEvents_up.sql @@ -1,18 +1,36 @@ +CREATE TABLE IF NOT EXISTS `ScheduledEvents` +( + `Id` BIGINT NOT NULL AUTO_INCREMENT, + `Interval` VARCHAR(255) NOT NULL, + `Name` VARCHAR(255) NOT NULL, + `Description` VARCHAR(255) NOT NULL, + `ChannelId` BIGINT NULL, + `StartTime` DATETIME(6) NOT NULL, + `EndTime` DATETIME(6) NULL, + `EntityType` ENUM ('1','2','3') NOT NULL, + `Location` VARCHAR(255) NULL, + `ServerId` BIGINT, + `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6), + `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + PRIMARY KEY (`Id`), + FOREIGN KEY (`ServerId`) REFERENCES `Servers` (`ServerId`) +); + CREATE TABLE IF NOT EXISTS `ScheduledEventsHistory` ( - `Id` BIGINT(20) NOT NULL, - `Interval` VARCHAR(255) NOT NULL, - `Name` VARCHAR(255) NOT NULL, - `Description` VARCHAR(255) NOT NULL, - `ChannelId` BIGINT NULL, - `StartTime` DATETIME(6) NOT NULL, - `EndTime` DATETIME(6) NULL, - `EntityType` ENUM ('1','2','3') NOT NULL, - `Location` VARCHAR(255) NULL, + `Id` BIGINT(20) NOT NULL, + `Interval` VARCHAR(255) NOT NULL, + `Name` VARCHAR(255) NOT NULL, + `Description` VARCHAR(255) NOT NULL, + `ChannelId` BIGINT NULL, + `StartTime` DATETIME(6) NOT NULL, + `EndTime` DATETIME(6) NULL, + `EntityType` ENUM ('1','2','3') NOT NULL, + `Location` VARCHAR(255) NULL, `ServerId` BIGINT(20) DEFAULT NULL, `Deleted` BOOL DEFAULT FALSE, - `DateFrom` DATETIME(6) NOT NULL, - `DateTo` DATETIME(6) NOT NULL + `DateFrom` DATETIME(6) NOT NULL, + `DateTo` DATETIME(6) NOT NULL ); DROP TRIGGER IF EXISTS `TR_ScheduledEventsUpdate`; diff --git a/bot/src/modules/achievements/achievements.json b/bot/src/modules/achievements/achievements.json index acea20a4..911cf740 100644 --- a/bot/src/modules/achievements/achievements.json +++ b/bot/src/modules/achievements/achievements.json @@ -16,10 +16,10 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=1.2.1" + "cpl-core>=1.2.dev410" ], "DevDependencies": [ - "cpl-cli>=1.2.1" + "cpl-cli>=1.2.dev410" ], "PythonVersion": ">=3.10.4", "PythonPath": {}, diff --git a/bot/src/modules/config/config.json b/bot/src/modules/config/config.json index 301f4630..6a80a8c4 100644 --- a/bot/src/modules/config/config.json +++ b/bot/src/modules/config/config.json @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=1.2.1" + "cpl-core>=1.2.dev410" ], "DevDependencies": [ - "cpl-cli>=1.2.1" + "cpl-cli>=1.2.dev410" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/bot/src/modules/short_role_name/short-role-name.json b/bot/src/modules/short_role_name/short-role-name.json index 57329ee1..23b81e41 100644 --- a/bot/src/modules/short_role_name/short-role-name.json +++ b/bot/src/modules/short_role_name/short-role-name.json @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=1.2.1" + "cpl-core>=1.2.dev410" ], "DevDependencies": [ - "cpl-cli>=1.2.1" + "cpl-cli>=1.2.dev410" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/bot/src/modules/special_offers/special-offers.json b/bot/src/modules/special_offers/special-offers.json index 8def3776..cd6b44b1 100644 --- a/bot/src/modules/special_offers/special-offers.json +++ b/bot/src/modules/special_offers/special-offers.json @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=1.2.1" + "cpl-core>=1.2.dev410" ], "DevDependencies": [ - "cpl-cli>=1.2.1" + "cpl-cli>=1.2.dev410" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/bot/tools/migration_to_sql/migration-to-sql.json b/bot/tools/migration_to_sql/migration-to-sql.json index 5e4a62f8..6be85895 100644 --- a/bot/tools/migration_to_sql/migration-to-sql.json +++ b/bot/tools/migration_to_sql/migration-to-sql.json @@ -2,9 +2,9 @@ "ProjectSettings": { "Name": "migration-to-sql", "Version": { - "Major": "0", - "Minor": "0", - "Micro": "0" + "Major": "1", + "Minor": "2", + "Micro": "2" }, "Author": "", "AuthorEmail": "", @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2023.10.0" + "cpl-core>=1.2.dev410" ], "DevDependencies": [ - "cpl-cli>=2023.4.0.post3" + "cpl-cli>=1.2.dev410" ], "PythonVersion": ">=3.10.4", "PythonPath": {