Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transfer/deployments DB migration script #345

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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