Added fix migration #378

This commit is contained in:
Sven Heidemann 2023-09-28 09:08:52 +02:00
parent d1c79c95b2
commit 5e9cca5b1d
6 changed files with 165 additions and 144 deletions

View File

@ -13,6 +13,7 @@ from bot_data.migration.config_feature_flags_migration import ConfigFeatureFlags
from bot_data.migration.config_migration import ConfigMigration
from bot_data.migration.db_history_migration import DBHistoryMigration
from bot_data.migration.default_role_migration import DefaultRoleMigration
from bot_data.migration.fix_updates_migration import FixUpdatesMigration
from bot_data.migration.initial_migration import InitialMigration
from bot_data.migration.level_migration import LevelMigration
from bot_data.migration.remove_stats_migration import RemoveStatsMigration
@ -52,3 +53,4 @@ class StartupMigrationExtension(StartupExtensionABC):
services.add_transient(MigrationABC, ConfigFeatureFlagsMigration) # 15.08.2023 #334 - 1.1.0
services.add_transient(MigrationABC, DefaultRoleMigration) # 24.09.2023 #360 - 1.1.3
services.add_transient(MigrationABC, ShortRoleNameMigration) # 28.09.2023 #378 - 1.1.7
services.add_transient(MigrationABC, FixUpdatesMigration) # 28.09.2023 #378 - 1.1.7

View File

@ -24,8 +24,6 @@ class MigrationABC(ABC):
def downgrade(self):
pass
def _exec(self, file: str):
path = f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts"
sql = open(f"{path}/{file}").read()

View File

@ -14,6 +14,8 @@ CREATE TABLE IF NOT EXISTS `CFG_ServerHistory`
`HelpVoiceChannelId` BIGINT NOT NULL,
`TeamChannelId` BIGINT NOT NULL,
`LoginMessageChannelId` BIGINT NOT NULL,
`DefaultRoleId` BIGINT NULL,
`FeatureFlags` JSON NULL DEFAULT ('{}'),
`ServerId` BIGINT NOT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
@ -27,8 +29,7 @@ CREATE TRIGGER `TR_CFG_ServerUpdate`
ON `CFG_Server`
FOR EACH ROW
BEGIN
INSERT INTO `CFG_ServerHistory` (
`Id`,
INSERT INTO `CFG_ServerHistory` (`Id`,
`MessageDeleteTimer`,
`NotificationChatId`,
`MaxVoiceStateHours`,
@ -42,12 +43,12 @@ BEGIN
`HelpVoiceChannelId`,
`TeamChannelId`,
`LoginMessageChannelId`,
`DefaultRoleId`,
`FeatureFlags`,
`ServerId`,
`DateFrom`,
`DateTo`
)
VALUES (
OLD.Id,
`DateTo`)
VALUES (OLD.Id,
OLD.MessageDeleteTimer,
OLD.NotificationChatId,
OLD.MaxVoiceStateHours,
@ -61,10 +62,11 @@ BEGIN
OLD.HelpVoiceChannelId,
OLD.TeamChannelId,
OLD.LoginMessageChannelId,
OLD.DefaultRoleId,
OLD.FeatureFlags,
OLD.ServerId,
OLD.LastModifiedAt,
CURRENT_TIMESTAMP(6)
);
CURRENT_TIMESTAMP(6));
END;
DROP TRIGGER IF EXISTS `TR_CFG_ServerDelete`;
@ -74,8 +76,7 @@ CREATE TRIGGER `TR_CFG_ServerDelete`
ON `CFG_Server`
FOR EACH ROW
BEGIN
INSERT INTO `CFG_ServerHistory` (
`Id`,
INSERT INTO `CFG_ServerHistory` (`Id`,
`MessageDeleteTimer`,
`NotificationChatId`,
`MaxVoiceStateHours`,
@ -89,13 +90,13 @@ BEGIN
`HelpVoiceChannelId`,
`TeamChannelId`,
`LoginMessageChannelId`,
`DefaultRoleId`,
`ServerId`,
`FeatureFlags`,
`Deleted`,
`DateFrom`,
`DateTo`
)
VALUES (
OLD.Id,
`DateTo`)
VALUES (OLD.Id,
OLD.MessageDeleteTimer,
OLD.NotificationChatId,
OLD.MaxVoiceStateHours,
@ -109,9 +110,10 @@ BEGIN
OLD.HelpVoiceChannelId,
OLD.TeamChannelId,
OLD.LoginMessageChannelId,
OLD.DefaultRoleId,
OLD.FeatureFlags,
OLD.ServerId,
TRUE,
OLD.LastModifiedAt,
CURRENT_TIMESTAMP(6)
);
CURRENT_TIMESTAMP(6));
END;

View File

@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS `CFG_TechnicianHistory`
`WaitForRestart` BIGINT NOT NULL DEFAULT 8,
`WaitForShutdown` BIGINT NOT NULL DEFAULT 8,
`CacheMaxMessages` BIGINT NOT NULL DEFAULT 1000000,
`FeatureFlags` JSON NULL DEFAULT ('{}'),
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
@ -17,24 +18,22 @@ CREATE TRIGGER `TR_CFG_TechnicianUpdate`
ON `CFG_Technician`
FOR EACH ROW
BEGIN
INSERT INTO `CFG_TechnicianHistory` (
`Id`,
INSERT INTO `CFG_TechnicianHistory` (`Id`,
`HelpCommandReferenceUrl`,
`WaitForRestart`,
`WaitForShutdown`,
`CacheMaxMessages`,
`FeatureFlags`,
`DateFrom`,
`DateTo`
)
VALUES (
OLD.Id,
`DateTo`)
VALUES (OLD.Id,
OLD.HelpCommandReferenceUrl,
OLD.WaitForRestart,
OLD.WaitForShutdown,
OLD.CacheMaxMessages,
OLD.FeatureFlags,
OLD.LastModifiedAt,
CURRENT_TIMESTAMP(6)
);
CURRENT_TIMESTAMP(6));
END;
DROP TRIGGER IF EXISTS `TR_CFG_TechnicianDelete`;
@ -44,24 +43,22 @@ CREATE TRIGGER `TR_CFG_TechnicianDelete`
ON `CFG_Technician`
FOR EACH ROW
BEGIN
INSERT INTO `CFG_TechnicianHistory` (
`Id`,
INSERT INTO `CFG_TechnicianHistory` (`Id`,
`HelpCommandReferenceUrl`,
`WaitForRestart`,
`WaitForShutdown`,
`CacheMaxMessages`,
`FeatureFlags`,
`Deleted`,
`DateFrom`,
`DateTo`
)
VALUES (
OLD.Id,
`DateTo`)
VALUES (OLD.Id,
OLD.HelpCommandReferenceUrl,
OLD.WaitForRestart,
OLD.WaitForShutdown,
OLD.CacheMaxMessages,
OLD.FeatureFlags,
TRUE,
OLD.LastModifiedAt,
CURRENT_TIMESTAMP(6)
);
CURRENT_TIMESTAMP(6));
END;

View File

@ -0,0 +1,22 @@
from bot_core.logging.database_logger import DatabaseLogger
from bot_data.abc.migration_abc import MigrationABC
from bot_data.db_context import DBContext
class FixUpdatesMigration(MigrationABC):
name = "1.1.7_FixUpdatesMigration"
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._exec("config/server.sql")
self._exec("config/technician.sql")
def downgrade(self):
pass

View File

@ -32,7 +32,7 @@ class ShortRoleNameMigration(MigrationABC):
)
)
self._exec("config/short_rule_names.sql")
self._exec("short_rule_names.sql")
def downgrade(self):
self._cursor.execute("DROP TABLE `ShortRoleNames`;")