From 986576f243228dc380ebca9036ec415e5e134a37 Mon Sep 17 00:00:00 2001 From: Silversthorn Date: Sun, 10 Mar 2024 12:43:52 +0000 Subject: [PATCH 1/7] Adding migration to fix the rework servers uuid issue --- .../20240310_fixing_rework_servers_uuid.py | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 app/migrations/20240310_fixing_rework_servers_uuid.py diff --git a/app/migrations/20240310_fixing_rework_servers_uuid.py b/app/migrations/20240310_fixing_rework_servers_uuid.py new file mode 100644 index 00000000..3c613e52 --- /dev/null +++ b/app/migrations/20240310_fixing_rework_servers_uuid.py @@ -0,0 +1,132 @@ +import datetime +import uuid +import peewee +import logging + +from app.classes.shared.console import Console +from app.classes.shared.migration import Migrator, MigrateHistory +from app.classes.models.management import Schedules, Backups +from app.classes.models.server_permissions import RoleServers + +logger = logging.getLogger(__name__) + + +def migrate(migrator: Migrator, database, **kwargs): + """ + Write your migrations here. + """ + db = database + + # ********************************************************************************** + # Servers New Model from Old (easier to migrate without dunmping Database) + # ********************************************************************************** + class Servers(peewee.Model): + server_id = peewee.CharField(primary_key=True, default=str(uuid.uuid4())) + created = peewee.DateTimeField(default=datetime.datetime.now) + server_name = peewee.CharField(default="Server", index=True) + path = peewee.CharField(default="") + backup_path = peewee.CharField(default="") + executable = peewee.CharField(default="") + log_path = peewee.CharField(default="") + execution_command = peewee.CharField(default="") + auto_start = peewee.BooleanField(default=0) + auto_start_delay = peewee.IntegerField(default=10) + crash_detection = peewee.BooleanField(default=0) + stop_command = peewee.CharField(default="stop") + executable_update_url = peewee.CharField(default="") + server_ip = peewee.CharField(default="127.0.0.1") + server_port = peewee.IntegerField(default=25565) + logs_delete_after = peewee.IntegerField(default=0) + type = peewee.CharField(default="minecraft-java") + show_status = peewee.BooleanField(default=1) + created_by = peewee.IntegerField(default=-100) + shutdown_timeout = peewee.IntegerField(default=60) + ignored_exits = peewee.CharField(default="0") + + class Meta: + table_name = "servers" + database = db + + try: + logger.info("Migrating Data from Int to UUID (Fixing Issue)") + Console.info("Migrating Data from Int to UUID (Fixing Issue)") + + # Changes on Servers Roles Table + migrator.alter_column_type( + RoleServers, + "server_id", + peewee.ForeignKeyField( + Servers, + backref="role_server", + null=True, + field=peewee.CharField(primary_key=True, default=str(uuid.uuid4())), + ), + ) + + # Changes on Backups Table + migrator.alter_column_type( + Backups, + "server_id", + peewee.ForeignKeyField( + Servers, + backref="backup_server", + null=True, + field=peewee.CharField(primary_key=True, default=str(uuid.uuid4())), + ), + ) + + # Changes on SChedule Table + migrator.alter_column_type( + Schedules, + "server_id", + peewee.ForeignKeyField( + Servers, + backref="schedule_server", + null=True, + field=peewee.CharField(primary_key=True, default=str(uuid.uuid4())), + ), + ) + + migrator.run() + + logger.info("Migrating Data from Int to UUID (Fixing Issue) : SUCCESS") + Console.info("Migrating Data from Int to UUID (Fixing Issue) : SUCCESS") + + except Exception as ex: + logger.error("Error while migrating Data from Int to UUID (Fixing Issue)") + logger.error(ex) + Console.error("Error while migrating Data from Int to UUID (Fixing Issue)") + Console.error(ex) + last_migration = MigrateHistory.get_by_id(MigrateHistory.select().count()) + last_migration.delete() + return + + return + + +def rollback(migrator: Migrator, database, **kwargs): + """ + Write your rollback migrations here. + """ + db = database + + # Changes on Webhook Table + migrator.alter_column_type( + RoleServers, + "server_id", + peewee.IntegerField(null=True), + ) + + # Changes on Webhook Table + migrator.alter_column_type( + Backups, + "server_id", + peewee.IntegerField(null=True), + ) + + # Changes on Webhook Table + migrator.alter_column_type( + Schedules, + "server_id", + peewee.IntegerField(null=True), + ) From 1e2ec6b6438b3975388679d1c960089cadf2bb32 Mon Sep 17 00:00:00 2001 From: Silversthorn Date: Sun, 10 Mar 2024 12:49:35 +0000 Subject: [PATCH 2/7] Removing the up_one in the constructor to prevent running all migration each time we got a new one. It's handled by migration.up() function. This function was not creating fake migrations. --- app/classes/shared/migration.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/classes/shared/migration.py b/app/classes/shared/migration.py index 1adea4c6..12d072c9 100644 --- a/app/classes/shared/migration.py +++ b/app/classes/shared/migration.py @@ -369,11 +369,12 @@ class MigrationManager(object): @cached_property def migrator(self) -> Migrator: """ - Create migrator and setup it with fake migrations. + Create migrator """ migrator = Migrator(self.database) - for name in self.done: - self.up_one(name, migrator, True) + # Removing the up_one to prevent running all migration each time we got a new one. it's handled by migration.up + #for name in self.done: + # self.up_one(name, migrator, True) return migrator def compile(self, name, migrate="", rollback=""): From ae7d0991e40fcddddc507ceaa9afe5f60faf677b Mon Sep 17 00:00:00 2001 From: Silversthorn Date: Sun, 10 Mar 2024 12:59:04 +0000 Subject: [PATCH 3/7] Fixint lint issue --- app/classes/shared/migration.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/classes/shared/migration.py b/app/classes/shared/migration.py index 12d072c9..c840e257 100644 --- a/app/classes/shared/migration.py +++ b/app/classes/shared/migration.py @@ -372,7 +372,8 @@ class MigrationManager(object): Create migrator """ migrator = Migrator(self.database) - # Removing the up_one to prevent running all migration each time we got a new one. it's handled by migration.up + # Removing the up_one to prevent running all migrations + # each time we got a new one. It's handled by migration.up() function. #for name in self.done: # self.up_one(name, migrator, True) return migrator From 36de32e5b1c00a19c77eb537715d484bbb8335c8 Mon Sep 17 00:00:00 2001 From: Silversthorn Date: Sun, 10 Mar 2024 13:15:17 +0000 Subject: [PATCH 4/7] Trying to appease lint one more time --- app/classes/shared/migration.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/classes/shared/migration.py b/app/classes/shared/migration.py index c840e257..8f081982 100644 --- a/app/classes/shared/migration.py +++ b/app/classes/shared/migration.py @@ -372,9 +372,10 @@ class MigrationManager(object): Create migrator """ migrator = Migrator(self.database) - # Removing the up_one to prevent running all migrations - # each time we got a new one. It's handled by migration.up() function. - #for name in self.done: + # Removing the up_one to prevent running all + # migrations each time we got a new one. + # It's handled by migration.up() function. + # for name in self.done: # self.up_one(name, migrator, True) return migrator From dbe5581e5a6b477a75b297c344f57da445524624 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Sun, 10 Mar 2024 22:52:23 +0000 Subject: [PATCH 5/7] Appease Black --- app/classes/shared/migration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/classes/shared/migration.py b/app/classes/shared/migration.py index 8f081982..6a93802b 100644 --- a/app/classes/shared/migration.py +++ b/app/classes/shared/migration.py @@ -372,8 +372,8 @@ class MigrationManager(object): Create migrator """ migrator = Migrator(self.database) - # Removing the up_one to prevent running all - # migrations each time we got a new one. + # Removing the up_one to prevent running all + # migrations each time we got a new one. # It's handled by migration.up() function. # for name in self.done: # self.up_one(name, migrator, True) From 9704016c54db5858cc31061506cf4abb0dc4a35b Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Wed, 13 Mar 2024 17:47:07 -0400 Subject: [PATCH 6/7] Update schema for str uuid --- app/classes/web/routes/api/roles/index.py | 4 ++-- app/classes/web/routes/api/roles/role/index.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/classes/web/routes/api/roles/index.py b/app/classes/web/routes/api/roles/index.py index dce6f453..266afb23 100644 --- a/app/classes/web/routes/api/roles/index.py +++ b/app/classes/web/routes/api/roles/index.py @@ -17,7 +17,7 @@ create_role_schema = { "type": "object", "properties": { "server_id": { - "type": "integer", + "type": "string", "minimum": 1, }, "permissions": { @@ -47,7 +47,7 @@ basic_create_role_schema = { "type": "object", "properties": { "server_id": { - "type": "integer", + "type": "string", "minimum": 1, }, "permissions": { diff --git a/app/classes/web/routes/api/roles/role/index.py b/app/classes/web/routes/api/roles/role/index.py index 0dd7d6c8..5ed12d69 100644 --- a/app/classes/web/routes/api/roles/role/index.py +++ b/app/classes/web/routes/api/roles/role/index.py @@ -16,7 +16,7 @@ modify_role_schema = { "type": "object", "properties": { "server_id": { - "type": "integer", + "type": "string", "minimum": 1, }, "permissions": { @@ -46,7 +46,7 @@ basic_modify_role_schema = { "type": "object", "properties": { "server_id": { - "type": "integer", + "type": "string", "minimum": 1, }, "permissions": { From 5190fd51d5c9bdfa804ed6e5ee3df54039e6bb9c Mon Sep 17 00:00:00 2001 From: Zedifus Date: Mon, 18 Mar 2024 22:32:25 +0000 Subject: [PATCH 7/7] Update changelog !729 Also fix minor date discrepancy. --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 996acb40..1bee1408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,16 @@ # Changelog -## --- [4.3.1] - 2023/TBD +## --- [4.3.1] - 2024/TBD ### New features TBD ### Bug fixes -TBD +- Fix Server ID Rework for backups, schedules, and roles (INT ID to UUID migration) ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/729)) ### Tweaks TBD ### Lang TBD

-## --- [4.3.0] - 2023/03/09 +## --- [4.3.0] - 2024/03/09 ### Breaking Changes - This release includes database migrations that are not revertable. Once you update to this version you will not be able to rollback to a previous version. - In this release, we've implemented a breaking change to enhance server identification within Crafty: instead of relying on numerical integers (1, 2, 3, etc.), Servers are now uniquely identified by their UUIDs. Please adapt your API clients accordingly. @@ -34,7 +34,7 @@ TBD - Update `de_DE, en_EN, es_ES, fr_FR, he_IL, lol_EN, lv_LV, nl_BE pl_PL, th_TH, tr_TR, uk_UA, zh_CN` translations for `4.3.0` ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/715))

-## --- [4.2.3] - 2023/02/02 +## --- [4.2.3] - 2024/02/02 ### New features - Use Papermc Group's API for `paper` & `folia` builds in server builder ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/688)) - Allow omission of player count from Dashboard (e.g. for proxy servers) ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/692))