def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine # add column: instances = Table('instances', meta, autoload=True) volume_size = Column('volume_size', Integer()) flavor_id = Column('flavor_id', String(36)) instances.create_column(flavor_id) instances.create_column(volume_size)
def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine # pgsql <= 8.3 was lax about char->other casting but this was tightened up # in 8.4+. We now have to specify the USING clause for the cast to succeed. # NB: The generated sqlalchemy query doesn't support this, so this override # is needed. if migrate_engine.name == 'postgresql': migrate_engine.execute('ALTER TABLE instances ALTER COLUMN flavor_id ' 'TYPE INTEGER USING flavor_id::integer') else: instances = Table('instances', meta, autoload=True) #modify column instances.c.flavor_id.alter(type=Integer())
def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine modules = Table('modules', meta, autoload=True) is_nullable = True if migrate_engine.name == "sqlite" else False column = Column(COLUMN_NAME_1, Boolean(), nullable=is_nullable, default=0) modules.create_column(column) column = Column(COLUMN_NAME_2, Integer(), nullable=is_nullable, default=5) modules.create_column(column) column = Column(COLUMN_NAME_3, Boolean(), nullable=is_nullable, default=0) modules.create_column(column) modules.c.contents.alter(Text(length=4294967295)) # mark all non-visible, auto-apply and all-tenant modules as is_admin update(table=modules, values=dict(is_admin=1), whereclause="visible=0 or auto_apply=1 or tenant_id is null" ).execute()
from sqlalchemy.schema import Column from sqlalchemy.schema import MetaData from trove.db.sqlalchemy.migrate_repo.schema import create_tables from trove.db.sqlalchemy.migrate_repo.schema import DateTime from trove.db.sqlalchemy.migrate_repo.schema import drop_tables from trove.db.sqlalchemy.migrate_repo.schema import Integer from trove.db.sqlalchemy.migrate_repo.schema import String from trove.db.sqlalchemy.migrate_repo.schema import Table meta = MetaData() service_statuses = Table( 'service_statuses', meta, Column('id', String(36), primary_key=True, nullable=False), Column('instance_id', String(36), nullable=False), Column('status_id', Integer(), nullable=False), Column('status_description', String(64), nullable=False), Column('updated_at', DateTime())) def upgrade(migrate_engine): meta.bind = migrate_engine create_tables([service_statuses]) def downgrade(migrate_engine): meta.bind = migrate_engine drop_tables([service_statuses])
security_group_rules = Table( 'security_group_rules', meta, Column('id', String(length=36), primary_key=True, nullable=False), Column( 'group_id', String(length=36), ForeignKey('security_groups.id', ondelete="CASCADE", onupdate="CASCADE")), Column( 'parent_group_id', String(length=36), ForeignKey('security_groups.id', ondelete="CASCADE", onupdate="CASCADE")), Column('protocol', String(length=255)), Column('from_port', Integer()), Column('to_port', Integer()), Column('cidr', String(length=255)), Column('created', DateTime()), Column('updated', DateTime()), Column('deleted', Boolean(), default=0), Column('deleted_at', DateTime()), ) def upgrade(migrate_engine): meta.bind = migrate_engine Table( 'instances', meta, autoload=True,
from trove.db.sqlalchemy.migrate_repo.schema import String from trove.db.sqlalchemy.migrate_repo.schema import Table from trove.db.sqlalchemy import utils as db_utils logger = logging.getLogger('trove.db.sqlalchemy.migrate_repo.schema') meta = MetaData() clusters = Table( 'clusters', meta, Column('id', String(36), primary_key=True, nullable=False), Column('created', DateTime(), nullable=False), Column('updated', DateTime(), nullable=False), Column('name', String(255), nullable=False), Column('task_id', Integer(), nullable=False), Column('tenant_id', String(36), nullable=False), Column("datastore_version_id", String(36), ForeignKey('datastore_versions.id'), nullable=False), Column('deleted', Boolean()), Column('deleted_at', DateTime()), Index("clusters_tenant_id", "tenant_id"), Index("clusters_deleted", "deleted"), ) def upgrade(migrate_engine): meta.bind = migrate_engine Table('datastores', meta, autoload=True)
from sqlalchemy.schema import Column from sqlalchemy.schema import MetaData from sqlalchemy.schema import UniqueConstraint from trove.db.sqlalchemy.migrate_repo.schema import create_tables from trove.db.sqlalchemy.migrate_repo.schema import DateTime from trove.db.sqlalchemy.migrate_repo.schema import drop_tables from trove.db.sqlalchemy.migrate_repo.schema import Integer from trove.db.sqlalchemy.migrate_repo.schema import String from trove.db.sqlalchemy.migrate_repo.schema import Table meta = MetaData() usage_events = Table( 'usage_events', meta, Column('id', String(36), primary_key=True, nullable=False), Column('instance_name', String(36)), Column('tenant_id', String(36)), Column('nova_instance_id', String(36)), Column('instance_size', Integer()), Column('nova_volume_id', String(36)), Column('volume_size', Integer()), Column('end_time', DateTime()), Column('updated', DateTime())) def upgrade(migrate_engine): meta.bind = migrate_engine create_tables([usage_events]) def downgrade(migrate_engine): meta.bind = migrate_engine drop_tables([usage_events])
from sqlalchemy.schema import MetaData from trove.db.sqlalchemy.migrate_repo.schema import create_tables from trove.db.sqlalchemy.migrate_repo.schema import DateTime from trove.db.sqlalchemy.migrate_repo.schema import drop_tables from trove.db.sqlalchemy.migrate_repo.schema import Integer from trove.db.sqlalchemy.migrate_repo.schema import String from trove.db.sqlalchemy.migrate_repo.schema import Table meta = MetaData() instances = Table('instances', meta, Column('id', String(36), primary_key=True, nullable=False), Column('created', DateTime()), Column('updated', DateTime()), Column('name', String(255)), Column('hostname', String(255)), Column('compute_instance_id', String(36)), Column('task_id', Integer()), Column('task_description', String(32)), Column('task_start_time', DateTime()), Column('volume_id', String(36))) def upgrade(migrate_engine): meta.bind = migrate_engine create_tables([instances]) def downgrade(migrate_engine): meta.bind = migrate_engine drop_tables([instances])
from trove.db.sqlalchemy.migrate_repo.schema import DateTime from trove.db.sqlalchemy.migrate_repo.schema import Integer from trove.db.sqlalchemy.migrate_repo.schema import String from trove.db.sqlalchemy.migrate_repo.schema import Table meta = MetaData() quotas = Table('quotas', meta, Column('id', String(36), primary_key=True, nullable=False), Column('created', DateTime()), Column('updated', DateTime()), Column('tenant_id', String(36)), Column('resource', String(length=255), nullable=False), Column('hard_limit', Integer()), UniqueConstraint('tenant_id', 'resource')) quota_usages = Table('quota_usages', meta, Column('id', String(36), primary_key=True, nullable=False), Column('created', DateTime()), Column('updated', DateTime()), Column('tenant_id', String(36)), Column('in_use', Integer(), default=0), Column('reserved', Integer(), default=0), Column('resource', String(length=255), nullable=False), UniqueConstraint('tenant_id', 'resource')) reservations = Table('reservations', meta, Column('created', DateTime()),
from trove.db.sqlalchemy.migrate_repo.schema import create_tables from trove.db.sqlalchemy.migrate_repo.schema import DateTime from trove.db.sqlalchemy.migrate_repo.schema import drop_tables from trove.db.sqlalchemy.migrate_repo.schema import Integer from trove.db.sqlalchemy.migrate_repo.schema import String from trove.db.sqlalchemy.migrate_repo.schema import Table meta = MetaData() quotas = Table('quotas', meta, Column('id', String(36), primary_key=True, nullable=False), Column('created', DateTime()), Column('updated', DateTime()), Column('tenant_id', String(36)), Column('resource', String(length=255), nullable=False), Column('hard_limit', Integer()), UniqueConstraint('tenant_id', 'resource')) quota_usages = Table( 'quota_usages', meta, Column('id', String(36), primary_key=True, nullable=False), Column('created', DateTime()), Column('updated', DateTime()), Column('tenant_id', String(36)), Column('in_use', Integer(), default=0), Column('reserved', Integer(), default=0), Column('resource', String(length=255), nullable=False), UniqueConstraint('tenant_id', 'resource')) reservations = Table( 'reservations', meta, Column('created', DateTime()), Column('updated', DateTime()), Column('id', String(36), primary_key=True, nullable=False),
def downgrade(migrate_engine): meta.bind = migrate_engine instances = Table('instances', meta, autoload=True) instances.c.flavor_id.alter(Integer())
def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine instances = Table('instances', meta, autoload=True) #modify column instances.c.flavor_id.alter(type=Integer())