Als Nutzer möchte ich Datenänderungen nach verfolgen können #246 #248

Merged
Jonas merged 17 commits from #246 into 1.0.0 2023-03-14 18:31:37 +01:00
9 changed files with 37 additions and 66 deletions
Showing only changes of commit 5df0501505 - Show all commits

View File

@ -18,7 +18,7 @@
"Dependencies": [
"cpl-core==2022.12.1.post3",
"cpl-translation==2022.12.1",
"cpl-query==2022.12.2.post1",
"cpl-query==2022.12.2.post2",
"Flask==2.2.2",
"Flask-Classful==0.14.2",
"Flask-Cors==3.0.10",

View File

@ -3,6 +3,7 @@ from abc import ABC, abstractmethod
class MigrationABC(ABC):
name = None
prio = 0
@abstractmethod
def __init__(self):

View File

@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
class ApiKeyMigration(MigrationABC):
name = "1.0_ApiKeyMigration"
name = "1.0.0_ApiKeyMigration"
def __init__(self, logger: DatabaseLogger, db: DBContext):
MigrationABC.__init__(self)

View File

@ -7,6 +7,7 @@ from bot_data.db_context import DBContext
class DBHistoryMigration(MigrationABC):
name = "1.0.0_DBHistoryMigration"
prio = 1
def __init__(self, logger: DatabaseLogger, db: DBContext):
MigrationABC.__init__(self)
@ -14,66 +15,35 @@ class DBHistoryMigration(MigrationABC):
self._db = db
self._cursor = db.cursor
def _exec(self, file: str):
path = f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts"
sql = open(f"{path}/{file}").read()
for statement in sql.split("\n\n"):
self._cursor.execute(statement + ";")
def upgrade(self):
self._logger.debug(__name__, "Running upgrade")
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/api_keys.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/auth_users.sql").read()
)
self._cursor.execute(
open(
f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/auth_user_users_relation.sql"
).read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/auto_role_rules.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/auto_roles.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/clients.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/game_servers.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/known_users.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/levels.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/servers.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_game_idents.sql").read()
)
self._cursor.execute(
open(
f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_joined_game_servers.sql"
).read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_joined_servers.sql").read()
)
self._cursor.execute(
open(
f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_joined_voice_channel.sql"
).read()
)
self._cursor.execute(
open(
f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_message_count_per_hour.sql"
).read()
)
self._cursor.execute(open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/users.sql").read())
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_warnings.sql").read()
)
self._exec("api_keys.sql")
self._exec("auth_users.sql")
self._exec("auth_user_users_relation.sql")
self._exec("auto_role_rules.sql")
self._exec("auto_roles.sql")
self._exec("clients.sql")
self._exec("game_servers.sql")
self._exec("known_users.sql")
self._exec("levels.sql")
self._exec("servers.sql")
self._exec("user_game_idents.sql")
self._exec("user_joined_game_servers.sql")
self._exec("user_joined_servers.sql")
self._exec("user_joined_voice_channel.sql")
self._exec("user_message_count_per_hour.sql")
self._exec("users.sql")
self._exec("user_warnings.sql")
self._logger.debug(__name__, "Finished history upgrade")
def downgrade(self):
self._cursor.execute("DROP TABLE `ApiKeysHistory`;")

View File

@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
class RemoveStatsMigration(MigrationABC):
name = "1.0_RemoveStatsMigration"
name = "1.0.0_RemoveStatsMigration"
def __init__(self, logger: DatabaseLogger, db: DBContext):
MigrationABC.__init__(self)

View File

@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
class UserJoinedGameServerMigration(MigrationABC):
name = "1.0_UserJoinedGameServerMigration"
name = "1.0.0_UserJoinedGameServerMigration"
def __init__(self, logger: DatabaseLogger, db: DBContext):
MigrationABC.__init__(self)

View File

@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
class UserWarningMigration(MigrationABC):
name = "1.0_UserWarningMigration"
name = "1.0.0_UserWarningMigration"
def __init__(self, logger: DatabaseLogger, db: DBContext):
MigrationABC.__init__(self)

View File

@ -147,7 +147,7 @@ class Client(TableABC):
`DeletedMessageCount`,
`ReceivedCommandsCount`,
`MovedUsersCount`,
`ServerId`,
`ServerId`
) VALUES (
{self._discord_client_id},
{self._sent_message_count},

View File

@ -1,5 +1,3 @@
from typing import Type
from cpl_core.database.context import DatabaseContextABC
from cpl_core.dependency_injection import ServiceProviderABC
from cpl_query.extension import List
@ -22,7 +20,9 @@ class MigrationService:
self._db = db
self._cursor = db.cursor
self._migrations = List(type, MigrationABC.__subclasses__()).order_by(lambda x: x.name)
self._migrations: List[MigrationABC] = (
List(type, MigrationABC.__subclasses__()).order_by(lambda x: x.name).order_by(lambda x: x.prio)
)
def migrate(self):
self._logger.info(__name__, f"Running Migrations")