From 38e8498af149e3066a5ece51ef614dc1cf7f37fa Mon Sep 17 00:00:00 2001 From: Omar Abou Selo Date: Thu, 18 Apr 2024 10:40:00 +0300 Subject: [PATCH] Fix template id db migration (#159) * Set empty string as default for template id field * Stop charm execution if db migrations fail to avoid overwriting status --- backend/charm/src/charm.py | 1 + ...4_04_17_1118-624a270a03dc_add_template_id_to_test_case.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/charm/src/charm.py b/backend/charm/src/charm.py index edd60b65..f847528d 100755 --- a/backend/charm/src/charm.py +++ b/backend/charm/src/charm.py @@ -113,6 +113,7 @@ def _migrate_database(self): logger.error(e.stdout) logger.error(e.stderr) self.unit.status = BlockedStatus("Database migration failed") + raise SystemExit(0) def _on_database_changed(self, event): self._migrate_database() diff --git a/backend/migrations/versions/2024_04_17_1118-624a270a03dc_add_template_id_to_test_case.py b/backend/migrations/versions/2024_04_17_1118-624a270a03dc_add_template_id_to_test_case.py index 8a0f74e3..f70758af 100644 --- a/backend/migrations/versions/2024_04_17_1118-624a270a03dc_add_template_id_to_test_case.py +++ b/backend/migrations/versions/2024_04_17_1118-624a270a03dc_add_template_id_to_test_case.py @@ -17,7 +17,10 @@ def upgrade() -> None: - op.add_column("test_case", sa.Column("template_id", sa.String(), nullable=False)) + op.add_column( + "test_case", + sa.Column("template_id", sa.String(), nullable=False, server_default=""), + ) def downgrade() -> None: