Added default role to backend #360
This commit is contained in:
		@@ -12,6 +12,7 @@ from bot_data.migration.auto_role_migration import AutoRoleMigration
 | 
			
		||||
from bot_data.migration.config_feature_flags_migration import ConfigFeatureFlagsMigration
 | 
			
		||||
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.initial_migration import InitialMigration
 | 
			
		||||
from bot_data.migration.level_migration import LevelMigration
 | 
			
		||||
from bot_data.migration.remove_stats_migration import RemoveStatsMigration
 | 
			
		||||
@@ -48,3 +49,4 @@ class StartupMigrationExtension(StartupExtensionABC):
 | 
			
		||||
        services.add_transient(MigrationABC, AchievementsMigration)  # 14.06.2023 #268 - 1.1.0
 | 
			
		||||
        services.add_transient(MigrationABC, ConfigMigration)  # 19.07.2023 #127 - 1.1.0
 | 
			
		||||
        services.add_transient(MigrationABC, ConfigFeatureFlagsMigration)  # 15.08.2023 #334 - 1.1.0
 | 
			
		||||
        services.add_transient(MigrationABC, DefaultRoleMigration)  # 24.09.2023 #360 - 1.1.3
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								kdb-bot/src/bot_data/migration/default_role_migration.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								kdb-bot/src/bot_data/migration/default_role_migration.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
from bot_core.logging.database_logger import DatabaseLogger
 | 
			
		||||
from bot_data.abc.migration_abc import MigrationABC
 | 
			
		||||
from bot_data.db_context import DBContext
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DefaultRoleMigration(MigrationABC):
 | 
			
		||||
    name = "1.1.3_ConfigMigration"
 | 
			
		||||
 | 
			
		||||
    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"""
 | 
			
		||||
                    ALTER TABLE CFG_Server
 | 
			
		||||
                    ADD DefaultRoleId BIGINT NULL AFTER LoginMessageChannelId;
 | 
			
		||||
                """
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def downgrade(self):
 | 
			
		||||
        self._cursor.execute(
 | 
			
		||||
            str(
 | 
			
		||||
                f"""
 | 
			
		||||
                    ALTER TABLE CFG_Server DROP COLUMN DefaultRoleId;
 | 
			
		||||
                """
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
@@ -26,6 +26,7 @@ class ServerConfig(TableABC, ConfigurationModelABC):
 | 
			
		||||
        help_voice_channel_id: int,
 | 
			
		||||
        team_channel_id: int,
 | 
			
		||||
        login_message_channel_id: int,
 | 
			
		||||
        default_role_id: int,
 | 
			
		||||
        feature_flags: dict[FeatureFlagsEnum],
 | 
			
		||||
        server: Server,
 | 
			
		||||
        afk_channel_ids: List[int],
 | 
			
		||||
@@ -48,6 +49,7 @@ class ServerConfig(TableABC, ConfigurationModelABC):
 | 
			
		||||
        self._help_voice_channel_id = help_voice_channel_id
 | 
			
		||||
        self._team_channel_id = team_channel_id
 | 
			
		||||
        self._login_message_channel_id = login_message_channel_id
 | 
			
		||||
        self._default_role_id = default_role_id
 | 
			
		||||
        self._feature_flags = feature_flags
 | 
			
		||||
        self._server = server
 | 
			
		||||
        self._afk_channel_ids = afk_channel_ids
 | 
			
		||||
@@ -165,6 +167,14 @@ class ServerConfig(TableABC, ConfigurationModelABC):
 | 
			
		||||
    def login_message_channel_id(self, value: int):
 | 
			
		||||
        self._login_message_channel_id = value
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def default_role_id(self) -> int:
 | 
			
		||||
        return self._default_role_id
 | 
			
		||||
 | 
			
		||||
    @default_role_id.setter
 | 
			
		||||
    def default_role_id(self, value: int):
 | 
			
		||||
        self._default_role_id = value
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def feature_flags(self) -> dict[FeatureFlagsEnum]:
 | 
			
		||||
        return self._feature_flags
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ class ServerConfigHistory(HistoryTableABC):
 | 
			
		||||
        help_voice_channel_id: int,
 | 
			
		||||
        team_channel_id: int,
 | 
			
		||||
        login_message_channel_id: int,
 | 
			
		||||
        default_role_id: int,
 | 
			
		||||
        feature_flags: dict[str],
 | 
			
		||||
        server_id: int,
 | 
			
		||||
        deleted: bool,
 | 
			
		||||
@@ -40,6 +41,7 @@ class ServerConfigHistory(HistoryTableABC):
 | 
			
		||||
        self._help_voice_channel_id = help_voice_channel_id
 | 
			
		||||
        self._team_channel_id = team_channel_id
 | 
			
		||||
        self._login_message_channel_id = login_message_channel_id
 | 
			
		||||
        self._default_role_id = default_role_id
 | 
			
		||||
        self._feature_flags = feature_flags
 | 
			
		||||
        self._server_id = server_id
 | 
			
		||||
 | 
			
		||||
@@ -99,6 +101,10 @@ class ServerConfigHistory(HistoryTableABC):
 | 
			
		||||
    def login_message_channel_id(self) -> int:
 | 
			
		||||
        return self._login_message_channel_id
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def default_role_id(self) -> int:
 | 
			
		||||
        return self._default_role_id
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def feature_flags(self) -> dict[str]:
 | 
			
		||||
        return self._feature_flags
 | 
			
		||||
 
 | 
			
		||||
@@ -64,12 +64,13 @@ class ServerConfigRepositoryService(ServerConfigRepositoryABC):
 | 
			
		||||
            result[11],
 | 
			
		||||
            result[12],
 | 
			
		||||
            result[13],
 | 
			
		||||
            json.loads(result[14]),
 | 
			
		||||
            self._servers.get_server_by_id(result[15]),
 | 
			
		||||
            self._get_afk_channel_ids(result[15]),
 | 
			
		||||
            self._get_team_role_ids(result[15]),
 | 
			
		||||
            result[16],
 | 
			
		||||
            result[17],
 | 
			
		||||
            result[14],
 | 
			
		||||
            json.loads(result[15]),
 | 
			
		||||
            self._servers.get_server_by_id(result[16]),
 | 
			
		||||
            self._get_afk_channel_ids(result[17]),
 | 
			
		||||
            self._get_team_role_ids(result[18]),
 | 
			
		||||
            result[19],
 | 
			
		||||
            result[20],
 | 
			
		||||
            id=result[0],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,7 @@ type ServerConfig implements TableWithHistoryQuery {
 | 
			
		||||
    helpVoiceChannelId: String
 | 
			
		||||
    teamChannelId: String
 | 
			
		||||
    loginMessageChannelId: String
 | 
			
		||||
    defaultRoleId: String
 | 
			
		||||
    featureFlagCount: Int
 | 
			
		||||
    featureFlags: [FeatureFlag]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,7 @@ class ServerConfigQuery(DataQueryWithHistoryABC):
 | 
			
		||||
        self.set_field("helpVoiceChannelId", lambda config, *_: config.help_voice_channel_id)
 | 
			
		||||
        self.set_field("teamChannelId", lambda config, *_: config.team_channel_id)
 | 
			
		||||
        self.set_field("loginMessageChannelId", lambda config, *_: config.login_message_channel_id)
 | 
			
		||||
        self.set_field("defaultRoleId", lambda config, *_: config.default_role_id)
 | 
			
		||||
        self.add_collection(
 | 
			
		||||
            "featureFlag",
 | 
			
		||||
            lambda config, *_: List(any, [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags]),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user