From 596134e3ad3b96deca937b1dcb7b79dd80f3c32d Mon Sep 17 00:00:00 2001 From: Bo Tran Date: Thu, 31 Oct 2024 17:38:40 +0700 Subject: [PATCH] Follow up: Add Datastore Version Registry Extension When upgrading Trove, the trove-manage script fails to upgrade the database when the DBDatastoreVersion table is not empty. This patch will help us fix above error Change-Id: Ib615032747f89daf7f8500c7e2df4064fab05314 --- .../datastore-version-show-response.json | 36 +++++++++++-------- .../fix-db-migration-b47ae342b4645b66.yaml | 5 +++ trove/datastore/models.py | 3 +- ...dd_datastore_version_registry_extension.py | 6 +++- 4 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 releasenotes/notes/fix-db-migration-b47ae342b4645b66.yaml diff --git a/api-ref/source/samples/datastore-version-show-response.json b/api-ref/source/samples/datastore-version-show-response.json index bf6ca44eda..77f7543683 100644 --- a/api-ref/source/samples/datastore-version-show-response.json +++ b/api-ref/source/samples/datastore-version-show-response.json @@ -1,18 +1,26 @@ { "version": { - "datastore": "cc9ee471-e781-43bf-a796-423c5d549997", - "id": "4eb0179d-fe11-4556-9422-5267d2fc7625", - "links": [ - { - "href": "https://127.0.0.1:8779/v1.0/9f8dd5eacb074c9f87d2d822c9092aa5/datastores/versions/4eb0179d-fe11-4556-9422-5267d2fc7625", - "rel": "self" - }, - { - "href": "https://127.0.0.1:8779/datastores/versions/4eb0179d-fe11-4556-9422-5267d2fc7625", - "rel": "bookmark" - } - ], - "name": "12", - "version": "5.7.29" + "id": "800774c4-0505-4ae7-8cf9-aae131e065ae", + "name": "5.7", + "version": "5.7", + "links": [ + { + "href": "https://127.0.0.1:8779/v1.0/0600c20b16444bfa979b879b099805a1/datastores/versions/800774c4-0505-4ae7-8cf9-aae131e065ae", + "rel": "self" + }, + { + "href": "https://127.0.0.1:8779/datastores/versions/800774c4-0505-4ae7-8cf9-aae131e065ae", + "rel": "bookmark" + } + ], + "datastore": "3423e828-3355-48ef-9c16-5c41e7c196fb", + "active": true, + "packages": "", + "image": null, + "registry_ext": "trove.guestagent.datastore.mysql.manager.Manager", + "repl_strategy": "trove.guestagent.strategies.replication.mysql_gtid.MysqlGTIDReplication", + "image_tags": [ + "trove" + ] } } \ No newline at end of file diff --git a/releasenotes/notes/fix-db-migration-b47ae342b4645b66.yaml b/releasenotes/notes/fix-db-migration-b47ae342b4645b66.yaml new file mode 100644 index 0000000000..9ac9146169 --- /dev/null +++ b/releasenotes/notes/fix-db-migration-b47ae342b4645b66.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + fix a bug where the trove-manage script fails to upgrade + the database when the DBDatastoreVersion table is not empty. diff --git a/trove/datastore/models.py b/trove/datastore/models.py index 65c7dab20d..b54fd2945c 100644 --- a/trove/datastore/models.py +++ b/trove/datastore/models.py @@ -65,7 +65,8 @@ class DBCapabilityOverrides(dbmodels.DatabaseModelBase): class DBDatastoreVersion(dbmodels.DatabaseModelBase): _data_fields = ['datastore_id', 'name', 'image_id', 'image_tags', - 'packages', 'active', 'manager', 'version'] + 'packages', 'active', 'manager', 'version', + 'registry_ext', 'repl_strategy'] _table_name = 'datastore_versions' diff --git a/trove/db/sqlalchemy/migrations/versions/5c68b4fb3cd1_add_datastore_version_registry_extension.py b/trove/db/sqlalchemy/migrations/versions/5c68b4fb3cd1_add_datastore_version_registry_extension.py index 0093f3ac19..8856370afa 100644 --- a/trove/db/sqlalchemy/migrations/versions/5c68b4fb3cd1_add_datastore_version_registry_extension.py +++ b/trove/db/sqlalchemy/migrations/versions/5c68b4fb3cd1_add_datastore_version_registry_extension.py @@ -75,7 +75,11 @@ def upgrade() -> None: 'repl_namespace': repl_namespaces.get(dsv_manager, ''), 'repl_strategy': repl_strategies.get(dsv_manager, '') } - ds_versions_table = table("datastore_versions", column("", String)) + ds_versions_table = table( + "datastore_versions", + column("id", String), + column("registry_ext", String), + column("repl_strategy", String)) op.execute( ds_versions_table.update() .where(ds_versions_table.c.id == dsv_id)