Added feature flags config to technician settings #334
This commit is contained in:
@@ -31,10 +31,10 @@ class Program:
|
||||
.use_extension(StartupDiscordExtension)
|
||||
.use_extension(StartupModuleExtension)
|
||||
.use_extension(StartupMigrationExtension)
|
||||
.use_extension(DatabaseExtension)
|
||||
.use_extension(ConfigExtension)
|
||||
.use_extension(InitBotExtension)
|
||||
.use_extension(BootLogExtension)
|
||||
.use_extension(DatabaseExtension)
|
||||
.use_extension(AppApiExtension)
|
||||
.use_extension(CoreExtension)
|
||||
.use_startup(Startup)
|
||||
|
@@ -9,6 +9,7 @@ from bot_data.migration.api_key_migration import ApiKeyMigration
|
||||
from bot_data.migration.api_migration import ApiMigration
|
||||
from bot_data.migration.auto_role_fix1_migration import AutoRoleFix1Migration
|
||||
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.initial_migration import InitialMigration
|
||||
@@ -46,3 +47,4 @@ class StartupMigrationExtension(StartupExtensionABC):
|
||||
services.add_transient(MigrationABC, DBHistoryMigration) # 06.03.2023 #246 - 1.0.0
|
||||
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
|
||||
|
@@ -0,0 +1,33 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class ConfigFeatureFlagsMigration(MigrationABC):
|
||||
name = "1.1.0_ConfigFeatureFlagsMigration"
|
||||
|
||||
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(
|
||||
"""ALTER TABLE CFG_Technician ADD FeatureFlags JSON NULL DEFAULT JSON_OBJECT() AFTER CacheMaxMessages;"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
"""ALTER TABLE CFG_Server ADD FeatureFlags JSON NULL DEFAULT JSON_OBJECT() AFTER LoginMessageChannelId;"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._logger.debug(__name__, "Running downgrade")
|
||||
self._cursor.execute("ALTER TABLE CFG_Technician DROP COLUMN FeatureFlags;")
|
||||
self._cursor.execute("ALTER TABLE CFG_Server DROP COLUMN FeatureFlags;")
|
@@ -143,6 +143,8 @@ class ConfigMigration(MigrationABC):
|
||||
|
||||
def downgrade(self):
|
||||
self._logger.debug(__name__, "Running downgrade")
|
||||
self._server_downgrade()
|
||||
self._technician_downgrade()
|
||||
|
||||
def _server_downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `CFG_Server`;")
|
||||
|
@@ -4,6 +4,7 @@ from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_data.model.server import Server
|
||||
from bot_data.model.server_team_role_ids_config import ServerTeamRoleIdsConfig
|
||||
|
||||
@@ -24,6 +25,7 @@ class ServerConfig(TableABC, ConfigurationModelABC):
|
||||
help_voice_channel_id: int,
|
||||
team_channel_id: int,
|
||||
login_message_channel_id: int,
|
||||
feature_flags: dict[FeatureFlagsEnum],
|
||||
server: Server,
|
||||
afk_channel_ids: List[int],
|
||||
team_role_ids: List[ServerTeamRoleIdsConfig],
|
||||
@@ -45,6 +47,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._feature_flags = feature_flags
|
||||
self._server = server
|
||||
self._afk_channel_ids = afk_channel_ids
|
||||
self._team_role_ids = team_role_ids
|
||||
@@ -161,6 +164,14 @@ class ServerConfig(TableABC, ConfigurationModelABC):
|
||||
def login_message_channel_id(self, value: int):
|
||||
self._login_message_channel_id = value
|
||||
|
||||
@property
|
||||
def feature_flags(self) -> dict[FeatureFlagsEnum]:
|
||||
return self._feature_flags
|
||||
|
||||
@feature_flags.setter
|
||||
def feature_flags(self, value: dict[FeatureFlagsEnum]):
|
||||
self._feature_flags = value
|
||||
|
||||
@property
|
||||
def afk_channel_ids(self) -> List[int]:
|
||||
return self._afk_channel_ids
|
||||
|
@@ -17,6 +17,7 @@ class ServerConfigHistory(HistoryTableABC):
|
||||
help_voice_channel_id: int,
|
||||
team_channel_id: int,
|
||||
login_message_channel_id: int,
|
||||
feature_flags: dict[str],
|
||||
server_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
@@ -39,6 +40,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._feature_flags = feature_flags
|
||||
self._server_id = server_id
|
||||
|
||||
self._deleted = deleted
|
||||
@@ -97,6 +99,10 @@ class ServerConfigHistory(HistoryTableABC):
|
||||
def login_message_channel_id(self) -> int:
|
||||
return self._login_message_channel_id
|
||||
|
||||
@property
|
||||
def feature_flags(self) -> dict[str]:
|
||||
return self._feature_flags
|
||||
|
||||
@property
|
||||
def server_id(self) -> int:
|
||||
return self._server_id
|
||||
|
@@ -1,9 +1,12 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
|
||||
|
||||
class TechnicianConfig(TableABC, ConfigurationModelABC):
|
||||
def __init__(
|
||||
@@ -12,6 +15,7 @@ class TechnicianConfig(TableABC, ConfigurationModelABC):
|
||||
wait_for_restart: int,
|
||||
wait_for_shutdown: int,
|
||||
cache_max_messages: int,
|
||||
feature_flags: dict[FeatureFlagsEnum],
|
||||
technician_ids: List[int],
|
||||
ping_urls: List[str],
|
||||
created_at: datetime = None,
|
||||
@@ -23,6 +27,7 @@ class TechnicianConfig(TableABC, ConfigurationModelABC):
|
||||
self._wait_for_restart = wait_for_restart
|
||||
self._wait_for_shutdown = wait_for_shutdown
|
||||
self._cache_max_messages = cache_max_messages
|
||||
self._feature_flags = feature_flags
|
||||
self._technician_ids = technician_ids
|
||||
self._ping_urls = ping_urls
|
||||
|
||||
@@ -66,6 +71,14 @@ class TechnicianConfig(TableABC, ConfigurationModelABC):
|
||||
def cache_max_messages(self, value: int):
|
||||
self._cache_max_messages = value
|
||||
|
||||
@property
|
||||
def feature_flags(self) -> dict[FeatureFlagsEnum]:
|
||||
return self._feature_flags
|
||||
|
||||
@feature_flags.setter
|
||||
def feature_flags(self, value: dict[FeatureFlagsEnum]):
|
||||
self._feature_flags = value
|
||||
|
||||
@property
|
||||
def technician_ids(self) -> List[int]:
|
||||
return self._technician_ids
|
||||
@@ -104,12 +117,13 @@ class TechnicianConfig(TableABC, ConfigurationModelABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `CFG_Technician` (
|
||||
`HelpCommandReferenceUrl`, `WaitForRestart`, `WaitForShutdown`, `CacheMaxMessages`
|
||||
`HelpCommandReferenceUrl`, `WaitForRestart`, `WaitForShutdown`, `CacheMaxMessages`, `FeatureFlags`
|
||||
) VALUES (
|
||||
'{self._help_command_reference_url}',
|
||||
{self._wait_for_restart},
|
||||
{self._wait_for_shutdown},
|
||||
{self._cache_max_messages}
|
||||
{self._cache_max_messages},
|
||||
'{json.dumps(self._feature_flags)}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -122,7 +136,8 @@ class TechnicianConfig(TableABC, ConfigurationModelABC):
|
||||
SET `HelpCommandReferenceUrl` = '{self._help_command_reference_url}',
|
||||
`WaitForRestart` = {self._wait_for_restart},
|
||||
`WaitForShutdown` = {self._wait_for_shutdown},
|
||||
`CacheMaxMessages` = {self._cache_max_messages}
|
||||
`CacheMaxMessages` = {self._cache_max_messages},
|
||||
`FeatureFlags` = '{json.dumps(self._feature_flags)}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import json
|
||||
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
@@ -62,11 +64,12 @@ class ServerConfigRepositoryService(ServerConfigRepositoryABC):
|
||||
result[11],
|
||||
result[12],
|
||||
result[13],
|
||||
self._servers.get_server_by_id(result[14]),
|
||||
self._get_afk_channel_ids(result[14]),
|
||||
self._get_team_role_ids(result[14]),
|
||||
result[15],
|
||||
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],
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
|
@@ -48,6 +48,7 @@ class ServerConfigSeeder(DataSeederABC):
|
||||
guild.system_channel.id,
|
||||
guild.system_channel.id,
|
||||
guild.system_channel.id,
|
||||
{},
|
||||
server,
|
||||
[],
|
||||
[],
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import json
|
||||
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
@@ -41,10 +43,11 @@ class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC):
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
json.loads(result[5]),
|
||||
self._get_technician_ids(),
|
||||
self._get_technician_ping_urls(),
|
||||
result[5],
|
||||
result[6],
|
||||
result[7],
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
|
@@ -32,6 +32,7 @@ class TechnicianConfigSeeder(DataSeederABC):
|
||||
8,
|
||||
8,
|
||||
1000000,
|
||||
{},
|
||||
List(int, [240160344557879316]),
|
||||
List(str, ["www.google.com", "www.sh-edraft.de", "www.keksdose-gaming.de"]),
|
||||
)
|
||||
|
9
kdb-bot/src/bot_graphql/model/featureFlags.gql
Normal file
9
kdb-bot/src/bot_graphql/model/featureFlags.gql
Normal file
@@ -0,0 +1,9 @@
|
||||
type FeatureFlag {
|
||||
key: String
|
||||
value: Boolean
|
||||
}
|
||||
|
||||
input FeatureFlagInput {
|
||||
key: String
|
||||
value: Boolean
|
||||
}
|
@@ -4,6 +4,7 @@ type TechnicianConfig implements TableWithHistoryQuery {
|
||||
waitForRestart: Int
|
||||
waitForShutdown: Int
|
||||
cacheMaxMessages: Int
|
||||
featureFlags: [FeatureFlag]
|
||||
pingURLs: [String]
|
||||
technicianIds: [String]
|
||||
|
||||
@@ -21,6 +22,7 @@ type TechnicianConfigHistory implements HistoryTableQuery {
|
||||
waitForRestart: Int
|
||||
waitForShutdown: Int
|
||||
cacheMaxMessages: Int
|
||||
featureFlags: [FeatureFlag]
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
@@ -55,6 +57,7 @@ input TechnicianConfigInput {
|
||||
waitForRestart: Int
|
||||
waitForShutdown: Int
|
||||
cacheMaxMessages: Int
|
||||
featureFlags: [FeatureFlagInput]
|
||||
pingURLs: [String]
|
||||
technicianIds: [String]
|
||||
}
|
@@ -49,6 +49,11 @@ class TechnicianConfigMutation(QueryABC):
|
||||
technician_config.cache_max_messages = (
|
||||
input["cacheMaxMessages"] if "cacheMaxMessages" in input else technician_config.cache_max_messages
|
||||
)
|
||||
technician_config.feature_flags = (
|
||||
dict(zip([x["key"] for x in input["featureFlags"]], [x["value"] for x in input["featureFlags"]]))
|
||||
if "featureFlags" in input
|
||||
else technician_config.feature_flags
|
||||
)
|
||||
technician_config.ping_urls = (
|
||||
List(str, input["pingURLs"]) if "pingURLs" in input else technician_config.ping_urls
|
||||
)
|
||||
|
@@ -9,3 +9,7 @@ class TechnicianConfigHistoryQuery(HistoryQueryABC):
|
||||
self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart)
|
||||
self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown)
|
||||
self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages)
|
||||
self.set_field(
|
||||
"featureFlags",
|
||||
lambda config, *_: [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags],
|
||||
)
|
||||
|
@@ -16,6 +16,10 @@ class TechnicianConfigQuery(DataQueryWithHistoryABC):
|
||||
self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart)
|
||||
self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown)
|
||||
self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages)
|
||||
self.set_field(
|
||||
"featureFlags",
|
||||
lambda config, *_: [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags],
|
||||
)
|
||||
self.set_field("pingURLs", lambda config, *_: config.ping_urls)
|
||||
self.set_field("technicianIds", lambda config, *_: config.technician_ids)
|
||||
|
||||
|
Reference in New Issue
Block a user