def define_metadef_objects_table(meta): _constr_kwargs = {} if meta.bind.name == 'ibm_db_sa': _constr_kwargs['name'] = 'ix_objects_namespace_id_name' objects = Table('metadef_objects', meta, Column('id', Integer(), primary_key=True, nullable=False), Column('namespace_id', Integer(), ForeignKey('metadef_namespaces.id'), nullable=False), Column('name', String(80), nullable=False), Column('description', Text()), Column('required', Text()), Column('schema', Text(), nullable=False), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime()), UniqueConstraint('namespace_id', 'name', **_constr_kwargs), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) if meta.bind.name != 'ibm_db_sa': Index('ix_objects_namespace_id_name', objects.c.namespace_id, objects.c.name) return objects
def define_tasks_table(meta): tasks = Table('tasks', meta, Column('id', String(36), primary_key=True, nullable=False), Column('type', String(30), nullable=False), Column('status', String(30), nullable=False), Column('owner', String(255), nullable=False), Column('input', Text()), # json blob Column('result', Text()), # json blob Column('message', Text()), Column('expires_at', DateTime(), nullable=True), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime()), Column('deleted_at', DateTime()), Column('deleted', Boolean(), nullable=False, default=False), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) Index('ix_tasks_type', tasks.c.type) Index('ix_tasks_status', tasks.c.status) Index('ix_tasks_owner', tasks.c.owner) Index('ix_tasks_deleted', tasks.c.deleted) Index('ix_tasks_updated_at', tasks.c.updated_at) return tasks
def define_metadef_namespaces_table(meta): # NOTE: For DB2 if UniqueConstraint is used when creating a table # an index will automatically be created. So, for DB2 specify the # index name up front. If not DB2 then create the Index. _constr_kwargs = {} if meta.bind.name == 'ibm_db_sa': _constr_kwargs['name'] = 'ix_namespaces_namespace' namespaces = Table('metadef_namespaces', meta, Column('id', Integer(), primary_key=True, nullable=False), Column('namespace', String(80), nullable=False), Column('display_name', String(80)), Column('description', Text()), Column('visibility', String(32)), Column('protected', Boolean()), Column('owner', String(255), nullable=False), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime()), UniqueConstraint('namespace', **_constr_kwargs), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) if meta.bind.name != 'ibm_db_sa': Index('ix_namespaces_namespace', namespaces.c.namespace) return namespaces
def define_artifact_blob_locations_table(meta): artifact_blob_locations = Table('artifact_blob_locations', meta, Column('id', String(36), primary_key=True, nullable=False), Column('blob_id', String(36), ForeignKey('artifact_blobs.id'), nullable=False), Column('value', Text(), nullable=False), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime(), nullable=False), Column('position', Integer()), Column('status', String(36), nullable=True), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) Index('ix_artifact_blob_locations_blob_id', artifact_blob_locations.c.blob_id) return artifact_blob_locations
def get_images_table(meta): """ Returns the Table object for the images table that corresponds to the images table definition of this version. """ images = Table('images', meta, Column('id', Integer(), primary_key=True, nullable=False), Column('name', String(255)), Column('disk_format', String(20)), Column('container_format', String(20)), Column('size', Integer()), Column('status', String(30), nullable=False), Column('is_public', Boolean(), nullable=False, default=False, index=True), Column('location', Text()), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime()), Column('deleted_at', DateTime()), Column('deleted', Boolean(), nullable=False, default=False, index=True), Column('checksum', String(32)), Column('owner', String(255)), Column('min_disk', Integer(), default=0), Column('min_ram', Integer(), default=0), mysql_engine='InnoDB', extend_existing=True) return images
def define_artifact_properties_table(meta): artifact_properties = Table('artifact_properties', meta, Column('id', String(36), primary_key=True, nullable=False), Column('artifact_id', String(36), ForeignKey('artifacts.id'), nullable=False), Column('name', String(255), nullable=False), Column('string_value', String(255)), Column('int_value', Integer()), Column('numeric_value', Numeric()), Column('bool_value', Boolean()), Column('text_value', Text()), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime(), nullable=False), Column('position', Integer()), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) Index('ix_artifact_properties_artifact_id', artifact_properties.c.artifact_id) Index('ix_artifact_properties_name', artifact_properties.c.name) return artifact_properties
def define_images_table(meta): images = Table('images', meta, Column('id', Integer(), primary_key=True, nullable=False), Column('name', String(255)), Column('type', String(30)), Column('size', Integer()), Column('status', String(30), nullable=False), Column('is_public', Boolean(), nullable=False, default=False, index=True), Column('location', Text()), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime()), Column('deleted_at', DateTime()), Column('deleted', Boolean(), nullable=False, default=False, index=True), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) return images
def define_task_info_table(meta): Table('tasks', meta, autoload=True) # NOTE(nikhil): input and result are stored as text in the DB. # SQLAlchemy marshals the data to/from JSON using custom type # JSONEncodedDict. It uses simplejson underneath. task_info = Table('task_info', meta, Column('task_id', String(36), ForeignKey('tasks.id'), primary_key=True, nullable=False), Column('input', Text()), Column('result', Text()), Column('message', Text()), mysql_engine='InnoDB', mysql_charset='utf8') return task_info
def define_image_properties_table(meta): (define_images_table, ) = from_migration_import('001_add_images_table', ['define_images_table']) images = define_images_table(meta) # noqa # NOTE(dperaza) DB2: specify the UniqueConstraint option when creating the # table will cause an index being created to specify the index # name and skip the step of creating another index with the same columns. # The index name is needed so it can be dropped and re-created later on. constr_kwargs = {} if meta.bind.name == 'ibm_db_sa': constr_kwargs['name'] = 'ix_image_properties_image_id_key' image_properties = Table('image_properties', meta, Column('id', Integer(), primary_key=True, nullable=False), Column('image_id', Integer(), ForeignKey('images.id'), nullable=False, index=True), Column('key', String(255), nullable=False), Column('value', Text()), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime()), Column('deleted_at', DateTime()), Column('deleted', Boolean(), nullable=False, default=False, index=True), UniqueConstraint('image_id', 'key', **constr_kwargs), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) if meta.bind.name != 'ibm_db_sa': Index('ix_image_properties_image_id_key', image_properties.c.image_id, image_properties.c.key) return image_properties
def define_artifacts_table(meta): artifacts = Table('artifacts', meta, Column('id', String(36), primary_key=True, nullable=False), Column('name', String(255), nullable=False), Column('type_name', String(255), nullable=False), Column('type_version_prefix', BigInteger(), nullable=False), Column('type_version_suffix', String(255)), Column('type_version_meta', String(255)), Column('version_prefix', BigInteger(), nullable=False), Column('version_suffix', String(255)), Column('version_meta', String(255)), Column('description', Text()), Column('visibility', String(32), nullable=False), Column('state', String(32), nullable=False), Column('owner', String(255), nullable=False), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime(), nullable=False), Column('deleted_at', DateTime()), Column('published_at', DateTime()), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) Index('ix_artifact_name_and_version', artifacts.c.name, artifacts.c.version_prefix, artifacts.c.version_suffix) Index('ix_artifact_type', artifacts.c.type_name, artifacts.c.type_version_prefix, artifacts.c.type_version_suffix) Index('ix_artifact_state', artifacts.c.state) Index('ix_artifact_owner', artifacts.c.owner) Index('ix_artifact_visibility', artifacts.c.visibility) return artifacts
def downgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine tasks_table = Table('tasks', meta, autoload=True) task_info_table = Table('task_info', meta, autoload=True) for col_name in TASKS_MIGRATE_COLUMNS: column = Column(col_name, Text()) column.create(tasks_table) task_info_records = task_info_table.select().execute().fetchall() for task_info in task_info_records: values = { 'input': task_info.input, 'result': task_info.result, 'message': task_info.message } tasks_table.update(values=values).where( tasks_table.c.id == task_info.task_id).execute() drop_tables([task_info_table])
def get_image_properties_table(meta): """ Returns the Table object for the image_properties table that corresponds to the image_properties table definition of this version. """ (get_images_table, ) = from_migration_import('004_add_checksum', ['get_images_table']) images = get_images_table(meta) # noqa image_properties = Table('image_properties', meta, Column('id', Integer(), primary_key=True, nullable=False), Column('image_id', Integer(), ForeignKey('images.id'), nullable=False, index=True), Column('name', String(255), nullable=False), Column('value', Text()), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime()), Column('deleted_at', DateTime()), Column('deleted', Boolean(), nullable=False, default=False, index=True), UniqueConstraint('image_id', 'name'), mysql_engine='InnoDB', extend_existing=True) return image_properties