
from sqlalchemy import Boolean, Column, MetaData, Table


def upgrade(migrate_engine):
    """Add shared_targets column to Volumes."""
    meta = MetaData()
    meta.bind = migrate_engine
    volumes = Table('volumes', meta, autoload=True)

    # NOTE(jdg):  We use a default of True because it's harmless for a device
    # that does NOT use shared_targets to be treated as if it does
    shared_targets = Column('shared_targets',
                            Boolean,
                            default=True)
    volumes.create_column(shared_targets)


from sqlalchemy import Boolean, Column, MetaData, Table


def upgrade(migrate_engine):
    """Add shared_targets column to Volumes."""
    meta = MetaData()
    meta.bind = migrate_engine
    volumes = Table('volumes', meta, autoload=True)

    # NOTE(jdg):  We use a default of True because it's harmless for a device
    # that does NOT use shared_targets to be treated as if it does
    if not hasattr(volumes.c, 'shared_targets'):
        volumes.create_column(Column('shared_targets', Boolean, default=True))

Add 'shared_targets' only when it doesn't exist
Add 'shared_targets' only when it doesn't exist

Add existence check before actually create it.

Change-Id: I96946f736d7263f80f7ad24f8cbbc9a09eb3cc63

  
  from sqlalchemy import Boolean, Column, MetaData, Table
  
  
  def upgrade(migrate_engine):
      """Add shared_targets column to Volumes."""
      meta = MetaData()
      meta.bind = migrate_engine
      volumes = Table('volumes', meta, autoload=True)
  
      # NOTE(jdg):  We use a default of True because it's harmless for a device
      # that does NOT use shared_targets to be treated as if it does
+     if not hasattr(volumes.c, 'shared_targets'):
+         volumes.create_column(Column('shared_targets', Boolean, default=True))
-     shared_targets = Column('shared_targets',
-                             Boolean,
-                             default=True)
-     volumes.create_column(shared_targets)
  
Add 'shared_targets' only when it doesn't exist
## Code Before:

from sqlalchemy import Boolean, Column, MetaData, Table


def upgrade(migrate_engine):
    """Add shared_targets column to Volumes."""
    meta = MetaData()
    meta.bind = migrate_engine
    volumes = Table('volumes', meta, autoload=True)

    # NOTE(jdg):  We use a default of True because it's harmless for a device
    # that does NOT use shared_targets to be treated as if it does
    shared_targets = Column('shared_targets',
                            Boolean,
                            default=True)
    volumes.create_column(shared_targets)

## Instruction:
Add 'shared_targets' only when it doesn't exist
## Code After:

from sqlalchemy import Boolean, Column, MetaData, Table


def upgrade(migrate_engine):
    """Add shared_targets column to Volumes."""
    meta = MetaData()
    meta.bind = migrate_engine
    volumes = Table('volumes', meta, autoload=True)

    # NOTE(jdg):  We use a default of True because it's harmless for a device
    # that does NOT use shared_targets to be treated as if it does
    if not hasattr(volumes.c, 'shared_targets'):
        volumes.create_column(Column('shared_targets', Boolean, default=True))
