コード例 #1
0
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)),
                   mysql_engine='InnoDB',
                   extend_existing=True)

    return images
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
def define_metadef_namespace_resource_types_table(meta):

    _constr_kwargs = {}
    if meta.bind.name == 'ibm_db_sa':
        _constr_kwargs['name'] = 'ix_metadef_ns_res_types_res_type_id_ns_id'

    metadef_associations = Table(
        'metadef_namespace_resource_types',
        meta,
        Column('resource_type_id',
               Integer(),
               ForeignKey('metadef_resource_types.id'),
               primary_key=True,
               nullable=False),
        Column('namespace_id',
               Integer(),
               ForeignKey('metadef_namespaces.id'),
               primary_key=True,
               nullable=False),
        Column('properties_target', String(80)),
        Column('prefix', String(80)),
        Column('created_at', DateTime(), nullable=False),
        Column('updated_at', DateTime()),
        UniqueConstraint('resource_type_id', 'namespace_id', **_constr_kwargs),
        mysql_engine='InnoDB',
        mysql_charset='utf8',
        extend_existing=True)

    if meta.bind.name != 'ibm_db_sa':
        Index('ix_metadef_ns_res_types_res_type_id_ns_id',
              metadef_associations.c.resource_type_id,
              metadef_associations.c.namespace_id)

    return metadef_associations
コード例 #8
0
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine
    (define_images_table, ) = from_migration_import('001_add_images_table',
                                                    ['define_images_table'])
    (define_image_properties_table, ) = from_migration_import(
        '002_add_image_properties_table', ['define_image_properties_table'])

    conn = migrate_engine.connect()
    images = define_images_table(meta)
    image_properties = define_image_properties_table(meta)

    # Steps to take, in this order:
    # 1) Move the existing type column from Image into
    #    ImageProperty for all image records that have a non-NULL
    #    type column
    # 2) Drop the type column in images
    # 3) Add the new columns to images

    # The below wackiness correlates to the following ANSI SQL:
    #   SELECT images.* FROM images
    #   LEFT JOIN image_properties
    #   ON images.id = image_properties.image_id
    #   AND image_properties.key = 'type'
    #   WHERE image_properties.image_id IS NULL
    #   AND images.type IS NOT NULL
    #
    # which returns all the images that have a type set
    # but that DO NOT yet have an image_property record
    # with key of type.
    from_stmt = [
        images.outerjoin(
            image_properties,
            and_(images.c.id == image_properties.c.image_id,
                 image_properties.c.key == 'type'))
    ]
    and_stmt = and_(image_properties.c.image_id == None, images.c.type != None)
    sel = select([images], from_obj=from_stmt).where(and_stmt)
    image_records = conn.execute(sel).fetchall()
    property_insert = image_properties.insert()
    for record in image_records:
        conn.execute(property_insert,
                     image_id=record.id,
                     key='type',
                     created_at=record.created_at,
                     deleted=False,
                     value=record.type)
    conn.close()

    disk_format = Column('disk_format', String(20))
    disk_format.create(images)
    container_format = Column('container_format', String(20))
    container_format.create(images)

    images.columns['type'].drop()
コード例 #9
0
def define_metadef_resource_types_table(meta):

    _constr_kwargs = {}
    if meta.bind.name == 'ibm_db_sa':
        _constr_kwargs['name'] = 'ix_metadef_resource_types_name'

    metadef_res_types = Table('metadef_resource_types',
                              meta,
                              Column('id',
                                     Integer(),
                                     primary_key=True,
                                     nullable=False),
                              Column('name', String(80), nullable=False),
                              Column('protected',
                                     Boolean(),
                                     nullable=False,
                                     default=False),
                              Column('created_at', DateTime(), nullable=False),
                              Column('updated_at', DateTime()),
                              UniqueConstraint('name', **_constr_kwargs),
                              mysql_engine='InnoDB',
                              mysql_charset='utf8',
                              extend_existing=True)

    if meta.bind.name != 'ibm_db_sa':
        Index('ix_metadef_resource_types_name', metadef_res_types.c.name)

    return metadef_res_types
コード例 #10
0
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
コード例 #11
0
def downgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    # Steps to take, in this order:
    # 1) Add type column back to Image
    # 2) Move the existing type properties from ImageProperty into
    #    Image.type
    # 3) Drop the disk_format and container_format columns in Image

    conn = migrate_engine.connect()
    images = get_images_table(meta)
    image_properties = get_image_properties_table(meta)

    type_col = Column('type', String(30))
    type_col.create(images)

    sel = select([image_properties]).where(image_properties.c.key == 'type')
    type_property_records = conn.execute(sel).fetchall()
    for record in type_property_records:
        upd = images.update().where(images.c.id == record.image_id).values(
            type=record.value)
        conn.execute(upd)
        dlt = image_properties.delete().where(
            image_properties.c.image_id == record.image_id)
        conn.execute(dlt)
    conn.close()

    images.columns['disk_format'].drop()
    images.columns['container_format'].drop()
コード例 #12
0
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    images = get_images_table(meta)

    checksum = Column('checksum', String(32))
    checksum.create(images)
コード例 #13
0
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    images = get_images_table(meta)

    owner = Column('owner', String(255))
    owner.create(images)
コード例 #14
0
def define_artifact_dependencies_table(meta):
    artifact_dependencies = Table('artifact_dependencies',
                                  meta,
                                  Column('id',
                                         String(36),
                                         primary_key=True,
                                         nullable=False),
                                  Column('artifact_source',
                                         String(36),
                                         ForeignKey('artifacts.id'),
                                         nullable=False),
                                  Column('artifact_dest',
                                         String(36),
                                         ForeignKey('artifacts.id'),
                                         nullable=False),
                                  Column('artifact_origin',
                                         String(36),
                                         ForeignKey('artifacts.id'),
                                         nullable=False),
                                  Column('is_direct',
                                         Boolean(),
                                         nullable=False),
                                  Column('position', Integer()),
                                  Column('name', String(36)),
                                  Column('created_at',
                                         DateTime(),
                                         nullable=False),
                                  Column('updated_at',
                                         DateTime(),
                                         nullable=False),
                                  mysql_engine='InnoDB',
                                  mysql_charset='utf8',
                                  extend_existing=True)

    Index('ix_artifact_dependencies_source_id',
          artifact_dependencies.c.artifact_source)
    Index('ix_artifact_dependencies_dest_id',
          artifact_dependencies.c.artifact_dest),
    Index('ix_artifact_dependencies_origin_id',
          artifact_dependencies.c.artifact_origin)
    Index('ix_artifact_dependencies_direct_dependencies',
          artifact_dependencies.c.artifact_source,
          artifact_dependencies.c.is_direct)
    return artifact_dependencies
コード例 #15
0
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
コード例 #16
0
def define_artifact_tags_table(meta):
    artifact_tags = Table('artifact_tags',
                          meta,
                          Column('id',
                                 String(36),
                                 primary_key=True,
                                 nullable=False),
                          Column('artifact_id',
                                 String(36),
                                 ForeignKey('artifacts.id'),
                                 nullable=False),
                          Column('value', String(255), nullable=False),
                          Column('created_at', DateTime(), nullable=False),
                          Column('updated_at', DateTime(), nullable=False),
                          mysql_engine='InnoDB',
                          mysql_charset='utf8',
                          extend_existing=True)

    Index('ix_artifact_tags_artifact_id', artifact_tags.c.artifact_id)
    Index('ix_artifact_tags_artifact_id_tag_value',
          artifact_tags.c.artifact_id, artifact_tags.c.value)

    return artifact_tags
コード例 #17
0
def define_artifact_blobs_table(meta):
    artifact_blobs = Table('artifact_blobs',
                           meta,
                           Column('id',
                                  String(36),
                                  primary_key=True,
                                  nullable=False),
                           Column('artifact_id',
                                  String(36),
                                  ForeignKey('artifacts.id'),
                                  nullable=False),
                           Column('size', BigInteger(), nullable=False),
                           Column('checksum', String(32)),
                           Column('name', String(255), nullable=False),
                           Column('item_key', String(329)),
                           Column('position', Integer()),
                           Column('created_at', DateTime(), nullable=False),
                           Column('updated_at', DateTime(), nullable=False),
                           mysql_engine='InnoDB',
                           mysql_charset='utf8',
                           extend_existing=True)
    Index('ix_artifact_blobs_artifact_id', artifact_blobs.c.artifact_id)
    Index('ix_artifact_blobs_name', artifact_blobs.c.name)
    return artifact_blobs
コード例 #18
0
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
コード例 #19
0
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
コード例 #20
0
def get_image_members_table(meta):
    images = get_images_table(meta)  # noqa

    image_members = Table('image_members',
                          meta,
                          Column('id',
                                 Integer(),
                                 primary_key=True,
                                 nullable=False),
                          Column('image_id',
                                 Integer(),
                                 ForeignKey('images.id'),
                                 nullable=False,
                                 index=True),
                          Column('member', String(255), nullable=False),
                          Column('can_share',
                                 Boolean(),
                                 nullable=False,
                                 default=False),
                          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', 'member'),
                          mysql_charset='utf8',
                          mysql_engine='InnoDB',
                          extend_existing=True)

    # DB2: an index has already been created for the UniqueConstraint option
    # specified on the Table() statement above.
    if meta.bind.name != "ibm_db_sa":
        Index('ix_image_members_image_id_member', image_members.c.image_id,
              image_members.c.member)

    return image_members
コード例 #21
0
def define_metadef_tags_table(meta):
    _constr_kwargs = {}
    metadef_tags = Table('metadef_tags',
                         meta,
                         Column('id',
                                Integer(),
                                primary_key=True,
                                nullable=False),
                         Column('namespace_id', Integer(), nullable=False),
                         Column('name', String(80), 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=False)

    if meta.bind.name != 'ibm_db_sa':
        Index('ix_tags_namespace_id_name', metadef_tags.c.namespace_id,
              metadef_tags.c.name)

    return metadef_tags
コード例 #22
0
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