Skip to content

Commit

Permalink
Fix transfer/deployments DB migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
Dany9966 committed Dec 12, 2024
1 parent dd8370d commit 7045415
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
37 changes: 31 additions & 6 deletions coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
Expand All @@ -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"')
3 changes: 0 additions & 3 deletions coriolis/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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

Expand Down

0 comments on commit 7045415

Please sign in to comment.