From 704541596147f4449fa5a3aaaeda11cfa2df6e5b Mon Sep 17 00:00:00 2001 From: Daniel Vincze Date: Wed, 11 Dec 2024 16:29:21 +0200 Subject: [PATCH] Fix transfer/deployments DB migration script --- .../versions/020_rename_tables.py | 37 ++++++++++++++++--- coriolis/db/sqlalchemy/models.py | 3 -- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py b/coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py index cc5e259e..2b9a163b 100644 --- a/coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py +++ b/coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py @@ -1,5 +1,10 @@ +from oslo_log import log as logging import sqlalchemy +from coriolis import utils + +LOG = logging.getLogger(__name__) + def upgrade(migrate_engine): meta = sqlalchemy.MetaData() @@ -8,10 +13,22 @@ def upgrade(migrate_engine): replica = sqlalchemy.Table('replica', meta, autoload=True) replica.rename('transfer') - migration = sqlalchemy.Table('migration', meta, autoload=True) - migration.rename('deployment') - migration.c.replica_id.alter(name='transfer_id', nullable=False) - migration.c.replication_count.drop() + deployment = sqlalchemy.Table( + 'deployment', meta, + sqlalchemy.Column("id", sqlalchemy.String(36), + sqlalchemy.ForeignKey( + 'base_transfer_action.base_id'), + primary_key=True), + sqlalchemy.Column("transfer_id", sqlalchemy.String(36), + sqlalchemy.ForeignKey('transfer.id'), + nullable=False), + mysql_engine="InnoDB", + mysql_charset="utf8") + try: + deployment.create() + except Exception: + deployment.drop() + raise replica_schedule = sqlalchemy.Table( 'replica_schedules', meta, autoload=True) @@ -25,6 +42,14 @@ def upgrade(migrate_engine): conn.execute( 'UPDATE base_transfer_action SET type = "transfer" ' 'WHERE type = "replica";') + conn.execute('UPDATE tasks_execution SET type = "transfer_execution"' + 'WHERE type = "replica_execution"') + conn.execute( + 'UPDATE tasks_execution SET type = "transfer_disks_delete"' + 'WHERE type = "replica_disks_delete"') + conn.execute( + 'UPDATE tasks_execution SET type = "deployment"' + 'WHERE type = "replica_deploy"') conn.execute( - 'UPDATE base_transfer_action SET type = "deployment" ' - 'WHERE type = "migration";') + 'UPDATE tasks_execution SET type = "transfer_update"' + 'WHERE type = "replica_update"') diff --git a/coriolis/db/sqlalchemy/models.py b/coriolis/db/sqlalchemy/models.py index 638d13d9..dd90b63a 100644 --- a/coriolis/db/sqlalchemy/models.py +++ b/coriolis/db/sqlalchemy/models.py @@ -361,8 +361,6 @@ class Deployment(BaseTransferAction): transfer = orm.relationship( Transfer, backref=orm.backref("deployments"), foreign_keys=[transfer_id]) - shutdown_instances = sqlalchemy.Column( - sqlalchemy.Boolean, nullable=False, default=False) __mapper_args__ = { 'polymorphic_identity': 'deployment', @@ -377,7 +375,6 @@ def to_dict(self, include_task_info=True, include_tasks=True): "id": self.id, "transfer_id": self.transfer_id, "transfer_scenario_type": self.transfer.scenario, - "shutdown_instances": self.shutdown_instances, }) return base