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 4978e86
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
32 changes: 26 additions & 6 deletions coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,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 +37,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 base_transfer_action SET type = "deployment" '
'WHERE type = "migration";')
'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 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
2 changes: 0 additions & 2 deletions coriolis/tests/db/sqlalchemy/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,9 @@ def test_to_dict(self):
deployment.id = mock.sentinel.id
deployment.transfer_id = transfer.id
deployment.transfer = transfer
deployment.shutdown_instances = mock.sentinel.shutdown_instances
expected_result = {
"id": mock.sentinel.id,
"transfer_id": mock.sentinel.transfer_id,
"shutdown_instances": mock.sentinel.shutdown_instances,
"transfer_scenario_type": transfer.scenario,
}

Expand Down

0 comments on commit 4978e86

Please sign in to comment.