Add column only when it doesn't exist

Add existence check before actually create the specific column.

Closes-Bug: #1797286

Change-Id: I7ecd65b2da3700bb02fd12d9f700260f2b708f45
This commit is contained in:
Yikun Jiang 2018-09-19 10:38:17 +08:00
parent ab911c1b47
commit e165980662
6 changed files with 18 additions and 10 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)