From e165980662d2aaa52abcdf10cb200c8db18432aa Mon Sep 17 00:00:00 2001 From: Yikun Jiang Date: Wed, 19 Sep 2018 10:38:17 +0800 Subject: [PATCH] Add column only when it doesn't exist Add existence check before actually create the specific column. Closes-Bug: #1797286 Change-Id: I7ecd65b2da3700bb02fd12d9f700260f2b708f45 --- .../versions/088_add_replication_info_to_cluster.py | 10 ++++++---- .../versions/089_add_cluster_name_image_cache.py | 3 ++- .../versions/090_add_race_preventer_to_workers.py | 3 ++- .../versions/099_add_connection_info_to_attachment.py | 3 ++- .../versions/103_message_action_detail_column.py | 6 ++++-- .../versions/117_add_encryption_key_id_to_backups.py | 3 ++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/088_add_replication_info_to_cluster.py b/cinder/db/sqlalchemy/migrate_repo/versions/088_add_replication_info_to_cluster.py index 0e1ef2b2fd7..52e654b0e88 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/088_add_replication_info_to_cluster.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/088_add_replication_info_to_cluster.py @@ -28,7 +28,9 @@ def upgrade(migrate_engine): active_backend_id = Column('active_backend_id', String(length=255)) frozen = Column('frozen', Boolean, nullable=False, default=False, server_default=expression.false()) - - clusters.create_column(replication_status) - clusters.create_column(frozen) - clusters.create_column(active_backend_id) + if not hasattr(clusters.c, 'replication_status'): + clusters.create_column(replication_status) + if not hasattr(clusters.c, 'frozen'): + clusters.create_column(frozen) + if not hasattr(clusters.c, 'active_backend_id'): + clusters.create_column(active_backend_id) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/089_add_cluster_name_image_cache.py b/cinder/db/sqlalchemy/migrate_repo/versions/089_add_cluster_name_image_cache.py index e05cfe69a58..94db5edfa50 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/089_add_cluster_name_image_cache.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/089_add_cluster_name_image_cache.py @@ -24,4 +24,5 @@ def upgrade(migrate_engine): image_cache = Table('image_volume_cache_entries', meta, autoload=True) cluster_name = Column('cluster_name', String(255), nullable=True) - image_cache.create_column(cluster_name) + if not hasattr(image_cache.c, 'cluster_name'): + image_cache.create_column(cluster_name) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/090_add_race_preventer_to_workers.py b/cinder/db/sqlalchemy/migrate_repo/versions/090_add_race_preventer_to_workers.py index 715e6782177..b3a27583a73 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/090_add_race_preventer_to_workers.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/090_add_race_preventer_to_workers.py @@ -24,4 +24,5 @@ def upgrade(migrate_engine): workers = Table('workers', meta, autoload=True) race_preventer = Column('race_preventer', Integer, nullable=False, default=0, server_default=text('0')) - race_preventer.create(workers, populate_default=True) + if not hasattr(workers.c, 'race_preventer'): + race_preventer.create(workers, populate_default=True) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/099_add_connection_info_to_attachment.py b/cinder/db/sqlalchemy/migrate_repo/versions/099_add_connection_info_to_attachment.py index 3993a17114b..ff8e8205de0 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/099_add_connection_info_to_attachment.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/099_add_connection_info_to_attachment.py @@ -19,4 +19,5 @@ def upgrade(migrate_engine): # Add connection_info column to attachment table attachment = Table('volume_attachment', meta, autoload=True) connection_info = Column('connection_info', Text) - attachment.create_column(connection_info) + if not hasattr(attachment.c, 'connection_info'): + attachment.create_column(connection_info) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/103_message_action_detail_column.py b/cinder/db/sqlalchemy/migrate_repo/versions/103_message_action_detail_column.py index 968cbb5fab7..f1d69fc048c 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/103_message_action_detail_column.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/103_message_action_detail_column.py @@ -19,5 +19,7 @@ def upgrade(migrate_engine): messages = Table('messages', meta, autoload=True) detail_id = Column('detail_id', String(10), nullable=True) action_id = Column('action_id', String(10), nullable=True) - messages.create_column(detail_id) - messages.create_column(action_id) + if not hasattr(messages.c, 'detail_id'): + messages.create_column(detail_id) + if not hasattr(messages.c, 'action_id'): + messages.create_column(action_id) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/117_add_encryption_key_id_to_backups.py b/cinder/db/sqlalchemy/migrate_repo/versions/117_add_encryption_key_id_to_backups.py index 126a3918c4c..91ac3a68695 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/117_add_encryption_key_id_to_backups.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/117_add_encryption_key_id_to_backups.py @@ -20,4 +20,5 @@ def upgrade(migrate_engine): backups = Table('backups', meta, autoload=True) encryption_key_id = Column('encryption_key_id', String(length=36)) - backups.create_column(encryption_key_id) + if not hasattr(backups.c, 'encryption_key_id'): + backups.create_column(encryption_key_id)