Esempio n. 1
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    op.bulk_insert(tables.logentrykind, [
        {
            "name": "change_tag_expiration"
        },
    ])
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "repositorybuildtrigger",
        sa.Column("successive_failure_count", sa.Integer(), server_default="0", nullable=False),
    )
    op.add_column(
        "repositorybuildtrigger",
        sa.Column(
            "successive_internal_error_count", sa.Integer(), server_default="0", nullable=False
        ),
    )
    # ### end Alembic commands ###

    op.bulk_insert(
        tables.disablereason,
        [
            {"id": 2, "name": "successive_build_failures"},
            {"id": 3, "name": "successive_build_internal_errors"},
        ],
    )

    # ### population of test data ### #
    tester.populate_column(
        "repositorybuildtrigger", "successive_failure_count", tester.TestDataType.Integer
    )
    tester.populate_column(
        "repositorybuildtrigger", "successive_internal_error_count", tester.TestDataType.Integer
    )
Esempio n. 3
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    for media_type in DOCKER_SCHEMA2_CONTENT_TYPES:
        op.bulk_insert(tables.mediatype,
                       [
                         {'name': media_type},
                       ])
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)

    op.bulk_insert(tables.notificationkind, [
        {
            'name': 'repo_mirror_sync_started'
        },
        {
            'name': 'repo_mirror_sync_success'
        },
        {
            'name': 'repo_mirror_sync_failed'
        },
    ])
    op.bulk_insert(tables.externalnotificationevent, [
        {
            'name': 'repo_mirror_sync_started'
        },
        {
            'name': 'repo_mirror_sync_success'
        },
        {
            'name': 'repo_mirror_sync_failed'
        },
    ])
Esempio n. 5
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    op.bulk_insert(tables.externalnotificationevent, [
        {
            "name": "build_cancelled"
        },
    ])
Esempio n. 6
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "user", sa.Column("company", UTF8CharField(length=255), nullable=True))
    op.add_column(
        "user",
        sa.Column("family_name", UTF8CharField(length=255), nullable=True))
    op.add_column(
        "user",
        sa.Column("given_name", UTF8CharField(length=255), nullable=True))
    ### end Alembic commands ###

    op.bulk_insert(tables.userpromptkind, [
        {
            "name": "enter_name"
        },
        {
            "name": "enter_company"
        },
    ])

    # ### population of test data ### #
    tester.populate_column("user", "company", tester.TestDataType.UTF8Char)
    tester.populate_column("user", "family_name", tester.TestDataType.UTF8Char)
    tester.populate_column("user", "given_name", tester.TestDataType.UTF8Char)
Esempio n. 7
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "appspecificauthtoken",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("uuid", sa.String(length=36), nullable=False),
        sa.Column("title", UTF8CharField(length=255), nullable=False),
        sa.Column("token_code", sa.String(length=255), nullable=False),
        sa.Column("created", sa.DateTime(), nullable=False),
        sa.Column("expiration", sa.DateTime(), nullable=True),
        sa.Column("last_accessed", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["user_id"], ["user.id"],
            name=op.f("fk_appspecificauthtoken_user_id_user")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_appspecificauthtoken")),
    )
    op.create_index("appspecificauthtoken_token_code",
                    "appspecificauthtoken", ["token_code"],
                    unique=True)
    op.create_index("appspecificauthtoken_user_id",
                    "appspecificauthtoken", ["user_id"],
                    unique=False)
    op.create_index(
        "appspecificauthtoken_user_id_expiration",
        "appspecificauthtoken",
        ["user_id", "expiration"],
        unique=False,
    )
    op.create_index("appspecificauthtoken_uuid",
                    "appspecificauthtoken", ["uuid"],
                    unique=False)
    # ### end Alembic commands ###

    op.bulk_insert(
        tables.logentrykind,
        [
            {
                "name": "create_app_specific_token"
            },
            {
                "name": "revoke_app_specific_token"
            },
        ],
    )

    # ### population of test data ### #
    tester.populate_table(
        "appspecificauthtoken",
        [
            ("user_id", tester.TestDataType.Foreign("user")),
            ("uuid", tester.TestDataType.UUID),
            ("title", tester.TestDataType.UTF8Char),
            ("token_code", tester.TestDataType.String),
            ("created", tester.TestDataType.DateTime),
            ("expiration", tester.TestDataType.DateTime),
            ("last_accessed", tester.TestDataType.DateTime),
        ],
    )
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "disablereason",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_disablereason")),
    )
    op.create_index("disablereason_name",
                    "disablereason", ["name"],
                    unique=True)

    op.bulk_insert(
        tables.disablereason,
        [
            {
                "id": 1,
                "name": "user_toggled"
            },
        ],
    )

    op.bulk_insert(tables.logentrykind, [
        {
            "name": "toggle_repo_trigger"
        },
    ])

    op.add_column(u"repositorybuildtrigger",
                  sa.Column("disabled_reason_id", sa.Integer(), nullable=True))
    op.add_column(
        u"repositorybuildtrigger",
        sa.Column("enabled",
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.expression.true()),
    )
    op.create_index(
        "repositorybuildtrigger_disabled_reason_id",
        "repositorybuildtrigger",
        ["disabled_reason_id"],
        unique=False,
    )
    op.create_foreign_key(
        op.f("fk_repositorybuildtrigger_disabled_reason_id_disablereason"),
        "repositorybuildtrigger",
        "disablereason",
        ["disabled_reason_id"],
        ["id"],
    )
    # ### end Alembic commands ###

    # ### population of test data ### #
    tester.populate_column("repositorybuildtrigger", "disabled_reason_id",
                           tester.TestDataType.Foreign("disablereason"))
    tester.populate_column("repositorybuildtrigger", "enabled",
                           tester.TestDataType.Boolean)
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('repository', sa.Column('trust_enabled', sa.Boolean(), nullable=False, server_default=sa.sql.expression.false()))
    ### end Alembic commands ###
    op.bulk_insert(tables.logentrykind, [
        {'name': 'change_repo_trust'},
    ])

    # ### population of test data ### #
    tester.populate_column('repository', 'trust_enabled', tester.TestDataType.Boolean)
Esempio n. 10
0
def upgrade(tables, tester, progress_reporter):
  op = ProgressWrapper(original_op, progress_reporter)
  op.add_column('repositorynotification', sa.Column('number_of_failures',
                                                    sa.Integer(),
                                                    nullable=False,
                                                    server_default='0'))
  op.bulk_insert(tables.logentrykind, [
    {'name': 'reset_repo_notification'},
  ])

  # ### population of test data ### #
  tester.populate_column('repositorynotification', 'number_of_failures', tester.TestDataType.Integer)
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "messages",
        sa.Column("media_type_id",
                  sa.Integer(),
                  nullable=False,
                  server_default="1"))
    op.add_column(
        "messages",
        sa.Column("severity",
                  sa.String(length=255),
                  nullable=False,
                  server_default="info"),
    )
    op.alter_column(
        "messages",
        "uuid",
        existing_type=mysql.VARCHAR(length=36),
        server_default="",
        nullable=False,
    )
    op.create_index("messages_media_type_id",
                    "messages", ["media_type_id"],
                    unique=False)
    op.create_index("messages_severity",
                    "messages", ["severity"],
                    unique=False)
    op.create_index("messages_uuid", "messages", ["uuid"], unique=False)
    op.create_foreign_key(
        op.f("fk_messages_media_type_id_mediatype"),
        "messages",
        "mediatype",
        ["media_type_id"],
        ["id"],
    )
    # ### end Alembic commands ###

    op.bulk_insert(tables.mediatype, [
        {
            "name": "text/markdown"
        },
    ])

    # ### population of test data ### #
    tester.populate_column("messages", "media_type_id",
                           tester.TestDataType.Foreign("mediatype"))
    tester.populate_column("messages", "severity", lambda: "info")
    tester.populate_column("messages", "uuid", tester.TestDataType.UUID)
Esempio n. 12
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'disablereason', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_disablereason')))
    op.create_index('disablereason_name',
                    'disablereason', ['name'],
                    unique=True)

    op.bulk_insert(
        tables.disablereason,
        [
            {
                'id': 1,
                'name': 'user_toggled'
            },
        ],
    )

    op.bulk_insert(tables.logentrykind, [
        {
            'name': 'toggle_repo_trigger'
        },
    ])

    op.add_column(u'repositorybuildtrigger',
                  sa.Column('disabled_reason_id', sa.Integer(), nullable=True))
    op.add_column(
        u'repositorybuildtrigger',
        sa.Column('enabled',
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.expression.true()))
    op.create_index('repositorybuildtrigger_disabled_reason_id',
                    'repositorybuildtrigger', ['disabled_reason_id'],
                    unique=False)
    op.create_foreign_key(
        op.f('fk_repositorybuildtrigger_disabled_reason_id_disablereason'),
        'repositorybuildtrigger', 'disablereason', ['disabled_reason_id'],
        ['id'])
    # ### end Alembic commands ###

    # ### population of test data ### #
    tester.populate_column('repositorybuildtrigger', 'disabled_reason_id',
                           tester.TestDataType.Foreign('disablereason'))
    tester.populate_column('repositorybuildtrigger', 'enabled',
                           tester.TestDataType.Boolean)
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "userpromptkind",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_userpromptkind")),
    )
    op.create_index("userpromptkind_name",
                    "userpromptkind", ["name"],
                    unique=False)
    op.create_table(
        "userprompt",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("kind_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["kind_id"], ["userpromptkind.id"],
            name=op.f("fk_userprompt_kind_id_userpromptkind")),
        sa.ForeignKeyConstraint(["user_id"], ["user.id"],
                                name=op.f("fk_userprompt_user_id_user")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_userprompt")),
    )
    op.create_index("userprompt_kind_id",
                    "userprompt", ["kind_id"],
                    unique=False)
    op.create_index("userprompt_user_id",
                    "userprompt", ["user_id"],
                    unique=False)
    op.create_index("userprompt_user_id_kind_id",
                    "userprompt", ["user_id", "kind_id"],
                    unique=True)
    ### end Alembic commands ###

    op.bulk_insert(tables.userpromptkind, [
        {
            "name": "confirm_username"
        },
    ])

    # ### population of test data ### #
    tester.populate_table(
        "userprompt",
        [
            ("user_id", tester.TestDataType.Foreign("user")),
            ("kind_id", tester.TestDataType.Foreign("userpromptkind")),
        ],
    )
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    op.create_table(
        "repositorykind",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_repositorykind")),
    )
    op.create_index("repositorykind_name",
                    "repositorykind", ["name"],
                    unique=True)

    op.bulk_insert(
        tables.repositorykind,
        [
            {
                "id": 1,
                "name": "image"
            },
            {
                "id": 2,
                "name": "application"
            },
        ],
    )

    op.add_column(
        u"repository",
        sa.Column("kind_id", sa.Integer(), nullable=False, server_default="1"))
    op.create_index("repository_kind_id",
                    "repository", ["kind_id"],
                    unique=False)
    op.create_foreign_key(
        op.f("fk_repository_kind_id_repositorykind"),
        "repository",
        "repositorykind",
        ["kind_id"],
        ["id"],
    )

    # ### population of test data ### #
    tester.populate_column("repository", "kind_id",
                           tester.TestDataType.Foreign("repositorykind"))
Esempio n. 15
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'userpromptkind', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_userpromptkind')))
    op.create_index('userpromptkind_name',
                    'userpromptkind', ['name'],
                    unique=False)
    op.create_table(
        'userprompt', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('kind_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['kind_id'], ['userpromptkind.id'],
            name=op.f('fk_userprompt_kind_id_userpromptkind')),
        sa.ForeignKeyConstraint(['user_id'], ['user.id'],
                                name=op.f('fk_userprompt_user_id_user')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_userprompt')))
    op.create_index('userprompt_kind_id',
                    'userprompt', ['kind_id'],
                    unique=False)
    op.create_index('userprompt_user_id',
                    'userprompt', ['user_id'],
                    unique=False)
    op.create_index('userprompt_user_id_kind_id',
                    'userprompt', ['user_id', 'kind_id'],
                    unique=True)
    ### end Alembic commands ###

    op.bulk_insert(tables.userpromptkind, [
        {
            'name': 'confirm_username'
        },
    ])

    # ### population of test data ### #
    tester.populate_table('userprompt', [
        ('user_id', tester.TestDataType.Foreign('user')),
        ('kind_id', tester.TestDataType.Foreign('userpromptkind')),
    ])
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'messages',
        sa.Column('media_type_id',
                  sa.Integer(),
                  nullable=False,
                  server_default='1'))
    op.add_column(
        'messages',
        sa.Column('severity',
                  sa.String(length=255),
                  nullable=False,
                  server_default='info'))
    op.alter_column('messages',
                    'uuid',
                    existing_type=mysql.VARCHAR(length=36),
                    server_default='',
                    nullable=False)
    op.create_index('messages_media_type_id',
                    'messages', ['media_type_id'],
                    unique=False)
    op.create_index('messages_severity',
                    'messages', ['severity'],
                    unique=False)
    op.create_index('messages_uuid', 'messages', ['uuid'], unique=False)
    op.create_foreign_key(op.f('fk_messages_media_type_id_mediatype'),
                          'messages', 'mediatype', ['media_type_id'], ['id'])
    # ### end Alembic commands ###

    op.bulk_insert(tables.mediatype, [
        {
            'name': 'text/markdown'
        },
    ])

    # ### population of test data ### #
    tester.populate_column('messages', 'media_type_id',
                           tester.TestDataType.Foreign('mediatype'))
    tester.populate_column('messages', 'severity', lambda: 'info')
    tester.populate_column('messages', 'uuid', tester.TestDataType.UUID)
Esempio n. 17
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'repositorybuildtrigger',
        sa.Column('successive_failure_count',
                  sa.Integer(),
                  server_default='0',
                  nullable=False))
    op.add_column(
        'repositorybuildtrigger',
        sa.Column('successive_internal_error_count',
                  sa.Integer(),
                  server_default='0',
                  nullable=False))
    # ### end Alembic commands ###

    op.bulk_insert(
        tables.disablereason,
        [
            {
                'id': 2,
                'name': 'successive_build_failures'
            },
            {
                'id': 3,
                'name': 'successive_build_internal_errors'
            },
        ],
    )

    # ### population of test data ### #
    tester.populate_column('repositorybuildtrigger',
                           'successive_failure_count',
                           tester.TestDataType.Integer)
    tester.populate_column('repositorybuildtrigger',
                           'successive_internal_error_count',
                           tester.TestDataType.Integer)
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    op.create_table(
        'repositorykind', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_repositorykind')))
    op.create_index('repositorykind_name',
                    'repositorykind', ['name'],
                    unique=True)

    op.bulk_insert(
        tables.repositorykind,
        [
            {
                'id': 1,
                'name': 'image'
            },
            {
                'id': 2,
                'name': 'application'
            },
        ],
    )

    op.add_column(
        u'repository',
        sa.Column('kind_id', sa.Integer(), nullable=False, server_default='1'))
    op.create_index('repository_kind_id',
                    'repository', ['kind_id'],
                    unique=False)
    op.create_foreign_key(op.f('fk_repository_kind_id_repositorykind'),
                          'repository', 'repositorykind', ['kind_id'], ['id'])

    # ### population of test data ### #
    tester.populate_column('repository', 'kind_id',
                           tester.TestDataType.Foreign('repositorykind'))
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('appspecificauthtoken',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('uuid', sa.String(length=36), nullable=False),
    sa.Column('title', UTF8CharField(length=255), nullable=False),
    sa.Column('token_code', sa.String(length=255), nullable=False),
    sa.Column('created', sa.DateTime(), nullable=False),
    sa.Column('expiration', sa.DateTime(), nullable=True),
    sa.Column('last_accessed', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_appspecificauthtoken_user_id_user')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_appspecificauthtoken'))
    )
    op.create_index('appspecificauthtoken_token_code', 'appspecificauthtoken', ['token_code'], unique=True)
    op.create_index('appspecificauthtoken_user_id', 'appspecificauthtoken', ['user_id'], unique=False)
    op.create_index('appspecificauthtoken_user_id_expiration', 'appspecificauthtoken', ['user_id', 'expiration'], unique=False)
    op.create_index('appspecificauthtoken_uuid', 'appspecificauthtoken', ['uuid'], unique=False)
    # ### end Alembic commands ###

    op.bulk_insert(tables.logentrykind, [
        {'name': 'create_app_specific_token'},
        {'name': 'revoke_app_specific_token'},
    ])

    # ### population of test data ### #
    tester.populate_table('appspecificauthtoken', [
        ('user_id', tester.TestDataType.Foreign('user')),
        ('uuid', tester.TestDataType.UUID),
        ('title', tester.TestDataType.UTF8Char),
        ('token_code', tester.TestDataType.String),
        ('created', tester.TestDataType.DateTime),
        ('expiration', tester.TestDataType.DateTime),
        ('last_accessed', tester.TestDataType.DateTime),
    ])
Esempio n. 20
0
def upgrade(tables, tester, progress_reporter):
  op = ProgressWrapper(original_op, progress_reporter)
  op.create_table(
    'tagkind',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_tagkind'))
  )
  op.create_index('tagkind_name', 'tagkind', ['name'], unique=True)

  op.create_table(
    'blobplacementlocation',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_blobplacementlocation'))
  )
  op.create_index('blobplacementlocation_name', 'blobplacementlocation', ['name'], unique=True)

  op.create_table(
    'blob',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('digest', sa.String(length=255), nullable=False),
    sa.Column('media_type_id', sa.Integer(), nullable=False),
    sa.Column('size', sa.BigInteger(), nullable=False),
    sa.Column('uncompressed_size', sa.BigInteger(), nullable=True),
    sa.ForeignKeyConstraint(['media_type_id'], ['mediatype.id'], name=op.f('fk_blob_media_type_id_mediatype')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_blob'))
  )
  op.create_index('blob_digest', 'blob', ['digest'], unique=True)
  op.create_index('blob_media_type_id', 'blob', ['media_type_id'], unique=False)

  op.create_table(
    'blobplacementlocationpreference',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['location_id'], ['blobplacementlocation.id'], name=op.f('fk_blobplacementlocpref_locid_blobplacementlocation')),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_blobplacementlocationpreference_user_id_user')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_blobplacementlocationpreference'))
  )
  op.create_index('blobplacementlocationpreference_location_id', 'blobplacementlocationpreference', ['location_id'], unique=False)
  op.create_index('blobplacementlocationpreference_user_id', 'blobplacementlocationpreference', ['user_id'], unique=False)

  op.create_table(
    'manifest',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('digest', sa.String(length=255), nullable=False),
    sa.Column('media_type_id', sa.Integer(), nullable=False),
    sa.Column('manifest_json', UTF8LongText, nullable=False),
    sa.ForeignKeyConstraint(['media_type_id'], ['mediatype.id'], name=op.f('fk_manifest_media_type_id_mediatype')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_manifest'))
  )
  op.create_index('manifest_digest', 'manifest', ['digest'], unique=True)
  op.create_index('manifest_media_type_id', 'manifest', ['media_type_id'], unique=False)

  op.create_table(
    'manifestlist',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('digest', sa.String(length=255), nullable=False),
    sa.Column('manifest_list_json', UTF8LongText, nullable=False),
    sa.Column('schema_version', UTF8CharField(length=255), nullable=False),
    sa.Column('media_type_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['media_type_id'], ['mediatype.id'], name=op.f('fk_manifestlist_media_type_id_mediatype')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlist'))
  )
  op.create_index('manifestlist_digest', 'manifestlist', ['digest'], unique=True)
  op.create_index('manifestlist_media_type_id', 'manifestlist', ['media_type_id'], unique=False)

  op.create_table(
    'bittorrentpieces',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('blob_id', sa.Integer(), nullable=False),
    sa.Column('pieces', UTF8LongText, nullable=False),
    sa.Column('piece_length', sa.BigInteger(), nullable=False),
    sa.ForeignKeyConstraint(['blob_id'], ['blob.id'], name=op.f('fk_bittorrentpieces_blob_id_blob')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_bittorrentpieces'))
  )
  op.create_index('bittorrentpieces_blob_id', 'bittorrentpieces', ['blob_id'], unique=False)
  op.create_index('bittorrentpieces_blob_id_piece_length', 'bittorrentpieces', ['blob_id', 'piece_length'], unique=True)

  op.create_table(
    'blobplacement',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('blob_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['blob_id'], ['blob.id'], name=op.f('fk_blobplacement_blob_id_blob')),
    sa.ForeignKeyConstraint(['location_id'], ['blobplacementlocation.id'], name=op.f('fk_blobplacement_location_id_blobplacementlocation')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_blobplacement'))
  )
  op.create_index('blobplacement_blob_id', 'blobplacement', ['blob_id'], unique=False)
  op.create_index('blobplacement_blob_id_location_id', 'blobplacement', ['blob_id', 'location_id'], unique=True)
  op.create_index('blobplacement_location_id', 'blobplacement', ['location_id'], unique=False)

  op.create_table(
    'blobuploading',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('uuid', sa.String(length=255), nullable=False),
    sa.Column('created', sa.DateTime(), nullable=False),
    sa.Column('repository_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('byte_count', sa.BigInteger(), nullable=False),
    sa.Column('uncompressed_byte_count', sa.BigInteger(), nullable=True),
    sa.Column('chunk_count', sa.BigInteger(), nullable=False),
    sa.Column('storage_metadata', UTF8LongText, nullable=True),
    sa.Column('sha_state', UTF8LongText, nullable=True),
    sa.Column('piece_sha_state', UTF8LongText, nullable=True),
    sa.Column('piece_hashes', UTF8LongText, nullable=True),
    sa.ForeignKeyConstraint(['location_id'], ['blobplacementlocation.id'], name=op.f('fk_blobuploading_location_id_blobplacementlocation')),
    sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], name=op.f('fk_blobuploading_repository_id_repository')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_blobuploading'))
  )
  op.create_index('blobuploading_created', 'blobuploading', ['created'], unique=False)
  op.create_index('blobuploading_location_id', 'blobuploading', ['location_id'], unique=False)
  op.create_index('blobuploading_repository_id', 'blobuploading', ['repository_id'], unique=False)
  op.create_index('blobuploading_repository_id_uuid', 'blobuploading', ['repository_id', 'uuid'], unique=True)
  op.create_index('blobuploading_uuid', 'blobuploading', ['uuid'], unique=True)

  op.create_table(
    'derivedimage',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('uuid', sa.String(length=255), nullable=False),
    sa.Column('source_manifest_id', sa.Integer(), nullable=False),
    sa.Column('derived_manifest_json', UTF8LongText, nullable=False),
    sa.Column('media_type_id', sa.Integer(), nullable=False),
    sa.Column('blob_id', sa.Integer(), nullable=False),
    sa.Column('uniqueness_hash', sa.String(length=255), nullable=False),
    sa.Column('signature_blob_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['blob_id'], ['blob.id'], name=op.f('fk_derivedimage_blob_id_blob')),
    sa.ForeignKeyConstraint(['media_type_id'], ['mediatype.id'], name=op.f('fk_derivedimage_media_type_id_mediatype')),
    sa.ForeignKeyConstraint(['signature_blob_id'], ['blob.id'], name=op.f('fk_derivedimage_signature_blob_id_blob')),
    sa.ForeignKeyConstraint(['source_manifest_id'], ['manifest.id'], name=op.f('fk_derivedimage_source_manifest_id_manifest')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_derivedimage'))
  )
  op.create_index('derivedimage_blob_id', 'derivedimage', ['blob_id'], unique=False)
  op.create_index('derivedimage_media_type_id', 'derivedimage', ['media_type_id'], unique=False)
  op.create_index('derivedimage_signature_blob_id', 'derivedimage', ['signature_blob_id'], unique=False)
  op.create_index('derivedimage_source_manifest_id', 'derivedimage', ['source_manifest_id'], unique=False)
  op.create_index('derivedimage_source_manifest_id_blob_id', 'derivedimage', ['source_manifest_id', 'blob_id'], unique=True)
  op.create_index('derivedimage_source_manifest_id_media_type_id_uniqueness_hash', 'derivedimage', ['source_manifest_id', 'media_type_id', 'uniqueness_hash'], unique=True)
  op.create_index('derivedimage_uniqueness_hash', 'derivedimage', ['uniqueness_hash'], unique=True)
  op.create_index('derivedimage_uuid', 'derivedimage', ['uuid'], unique=True)

  op.create_table(
    'manifestblob',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('manifest_id', sa.Integer(), nullable=False),
    sa.Column('blob_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['blob_id'], ['blob.id'], name=op.f('fk_manifestblob_blob_id_blob')),
    sa.ForeignKeyConstraint(['manifest_id'], ['manifest.id'], name=op.f('fk_manifestblob_manifest_id_manifest')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestblob'))
  )
  op.create_index('manifestblob_blob_id', 'manifestblob', ['blob_id'], unique=False)
  op.create_index('manifestblob_manifest_id', 'manifestblob', ['manifest_id'], unique=False)
  op.create_index('manifestblob_manifest_id_blob_id', 'manifestblob', ['manifest_id', 'blob_id'], unique=True)

  op.create_table(
    'manifestlabel',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('repository_id', sa.Integer(), nullable=False),
    sa.Column('annotated_id', sa.Integer(), nullable=False),
    sa.Column('label_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['annotated_id'], ['manifest.id'], name=op.f('fk_manifestlabel_annotated_id_manifest')),
    sa.ForeignKeyConstraint(['label_id'], ['label.id'], name=op.f('fk_manifestlabel_label_id_label')),
    sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], name=op.f('fk_manifestlabel_repository_id_repository')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlabel'))
  )
  op.create_index('manifestlabel_annotated_id', 'manifestlabel', ['annotated_id'], unique=False)
  op.create_index('manifestlabel_label_id', 'manifestlabel', ['label_id'], unique=False)
  op.create_index('manifestlabel_repository_id', 'manifestlabel', ['repository_id'], unique=False)
  op.create_index('manifestlabel_repository_id_annotated_id_label_id', 'manifestlabel', ['repository_id', 'annotated_id', 'label_id'], unique=True)

  op.create_table(
    'manifestlayer',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('blob_id', sa.Integer(), nullable=False),
    sa.Column('manifest_id', sa.Integer(), nullable=False),
    sa.Column('manifest_index', sa.BigInteger(), nullable=False),
    sa.Column('metadata_json', UTF8LongText, nullable=False),
    sa.ForeignKeyConstraint(['blob_id'], ['blob.id'], name=op.f('fk_manifestlayer_blob_id_blob')),
    sa.ForeignKeyConstraint(['manifest_id'], ['manifest.id'], name=op.f('fk_manifestlayer_manifest_id_manifest')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlayer'))
  )
  op.create_index('manifestlayer_blob_id', 'manifestlayer', ['blob_id'], unique=False)
  op.create_index('manifestlayer_manifest_id', 'manifestlayer', ['manifest_id'], unique=False)
  op.create_index('manifestlayer_manifest_id_manifest_index', 'manifestlayer', ['manifest_id', 'manifest_index'], unique=True)
  op.create_index('manifestlayer_manifest_index', 'manifestlayer', ['manifest_index'], unique=False)

  op.create_table(
    'manifestlistmanifest',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('manifest_list_id', sa.Integer(), nullable=False),
    sa.Column('manifest_id', sa.Integer(), nullable=False),
    sa.Column('operating_system', UTF8CharField(length=255), nullable=True),
    sa.Column('architecture', UTF8CharField(length=255), nullable=True),
    sa.Column('platform_json', UTF8LongText, nullable=True),
    sa.Column('media_type_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['manifest_id'], ['manifest.id'], name=op.f('fk_manifestlistmanifest_manifest_id_manifest')),
    sa.ForeignKeyConstraint(['manifest_list_id'], ['manifestlist.id'], name=op.f('fk_manifestlistmanifest_manifest_list_id_manifestlist')),
    sa.ForeignKeyConstraint(['media_type_id'], ['mediatype.id'], name=op.f('fk_manifestlistmanifest_media_type_id_mediatype')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlistmanifest'))
  )
  op.create_index('manifestlistmanifest_manifest_id', 'manifestlistmanifest', ['manifest_id'], unique=False)
  op.create_index('manifestlistmanifest_manifest_list_id', 'manifestlistmanifest', ['manifest_list_id'], unique=False)
  op.create_index('manifestlistmanifest_manifest_listid_os_arch_mtid', 'manifestlistmanifest', ['manifest_list_id', 'operating_system', 'architecture', 'media_type_id'], unique=False)
  op.create_index('manifestlistmanifest_manifest_listid_mtid', 'manifestlistmanifest', ['manifest_list_id', 'media_type_id'], unique=False)
  op.create_index('manifestlistmanifest_media_type_id', 'manifestlistmanifest', ['media_type_id'], unique=False)

  op.create_table(
    'tag',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', UTF8CharField(length=190), nullable=False),
    sa.Column('repository_id', sa.Integer(), nullable=False),
    sa.Column('manifest_list_id', sa.Integer(), nullable=True),
    sa.Column('lifetime_start', sa.BigInteger(), nullable=False),
    sa.Column('lifetime_end', sa.BigInteger(), nullable=True),
    sa.Column('hidden', sa.Boolean(), nullable=False),
    sa.Column('reverted', sa.Boolean(), nullable=False),
    sa.Column('protected', sa.Boolean(), nullable=False),
    sa.Column('tag_kind_id', sa.Integer(), nullable=False),
    sa.Column('linked_tag_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['linked_tag_id'], ['tag.id'], name=op.f('fk_tag_linked_tag_id_tag')),
    sa.ForeignKeyConstraint(['manifest_list_id'], ['manifestlist.id'], name=op.f('fk_tag_manifest_list_id_manifestlist')),
    sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], name=op.f('fk_tag_repository_id_repository')),
    sa.ForeignKeyConstraint(['tag_kind_id'], ['tagkind.id'], name=op.f('fk_tag_tag_kind_id_tagkind')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_tag'))
  )
  op.create_index('tag_lifetime_end', 'tag', ['lifetime_end'], unique=False)
  op.create_index('tag_linked_tag_id', 'tag', ['linked_tag_id'], unique=False)
  op.create_index('tag_manifest_list_id', 'tag', ['manifest_list_id'], unique=False)
  op.create_index('tag_repository_id', 'tag', ['repository_id'], unique=False)
  op.create_index('tag_repository_id_name_hidden', 'tag', ['repository_id', 'name', 'hidden'], unique=False)
  op.create_index('tag_repository_id_name_lifetime_end', 'tag', ['repository_id', 'name', 'lifetime_end'], unique=True)
  op.create_index('tag_repository_id_name', 'tag', ['repository_id', 'name'], unique=False)
  op.create_index('tag_tag_kind_id', 'tag', ['tag_kind_id'], unique=False)

  op.create_table(
    'manifestlayerdockerv1',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('manifest_layer_id', sa.Integer(), nullable=False),
    sa.Column('image_id', UTF8CharField(length=255), nullable=False),
    sa.Column('checksum', UTF8CharField(length=255), nullable=False),
    sa.Column('compat_json', UTF8LongText, nullable=False),
    sa.ForeignKeyConstraint(['manifest_layer_id'], ['manifestlayer.id'], name=op.f('fk_manifestlayerdockerv1_manifest_layer_id_manifestlayer')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlayerdockerv1'))
  )
  op.create_index('manifestlayerdockerv1_image_id', 'manifestlayerdockerv1', ['image_id'], unique=False)
  op.create_index('manifestlayerdockerv1_manifest_layer_id', 'manifestlayerdockerv1', ['manifest_layer_id'], unique=False)

  op.create_table(
    'manifestlayerscan',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('layer_id', sa.Integer(), nullable=False),
    sa.Column('scannable', sa.Boolean(), nullable=False),
    sa.Column('scanned_by', UTF8CharField(length=255), nullable=False),
    sa.ForeignKeyConstraint(['layer_id'], ['manifestlayer.id'], name=op.f('fk_manifestlayerscan_layer_id_manifestlayer')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlayerscan'))
  )
  op.create_index('manifestlayerscan_layer_id', 'manifestlayerscan', ['layer_id'], unique=True)

  blobplacementlocation_table = table('blobplacementlocation',
      column('id', sa.Integer()),
      column('name', sa.String()),
  )

  op.bulk_insert(
    blobplacementlocation_table,
    [
      {'name': 'local_eu'},
      {'name': 'local_us'},
    ],
  )

  op.bulk_insert(
    tables.mediatype,
    [
      {'name': 'application/vnd.cnr.blob.v0.tar+gzip'},
      {'name': 'application/vnd.cnr.package-manifest.helm.v0.json'},
      {'name': 'application/vnd.cnr.package-manifest.kpm.v0.json'},
      {'name': 'application/vnd.cnr.package-manifest.docker-compose.v0.json'},
      {'name': 'application/vnd.cnr.package.kpm.v0.tar+gzip'},
      {'name': 'application/vnd.cnr.package.helm.v0.tar+gzip'},
      {'name': 'application/vnd.cnr.package.docker-compose.v0.tar+gzip'},
      {'name': 'application/vnd.cnr.manifests.v0.json'},
      {'name': 'application/vnd.cnr.manifest.list.v0.json'},
    ],
  )

  tagkind_table = table('tagkind',
      column('id', sa.Integer()),
      column('name', sa.String()),
  )

  op.bulk_insert(
    tagkind_table,
    [
      {'id': 1, 'name': 'tag'},
      {'id': 2, 'name': 'release'},
      {'id': 3, 'name': 'channel'},
    ]
  )
def upgrade(tables, tester, progress_reporter):
  op = ProgressWrapper(original_op, progress_reporter)
  op.bulk_insert(tables.notificationkind,
                 [
                   {'name': 'build_cancelled'},
                 ])
Esempio n. 22
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "tagkind",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_tagkind")),
    )
    op.create_index("tagkind_name", "tagkind", ["name"], unique=True)
    op.create_table(
        "manifestchild",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("child_manifest_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["child_manifest_id"],
            ["manifest.id"],
            name=op.f("fk_manifestchild_child_manifest_id_manifest"),
        ),
        sa.ForeignKeyConstraint(
            ["manifest_id"], ["manifest.id"],
            name=op.f("fk_manifestchild_manifest_id_manifest")),
        sa.ForeignKeyConstraint(
            ["repository_id"],
            ["repository.id"],
            name=op.f("fk_manifestchild_repository_id_repository"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestchild")),
    )
    op.create_index("manifestchild_child_manifest_id",
                    "manifestchild", ["child_manifest_id"],
                    unique=False)
    op.create_index("manifestchild_manifest_id",
                    "manifestchild", ["manifest_id"],
                    unique=False)
    op.create_index(
        "manifestchild_manifest_id_child_manifest_id",
        "manifestchild",
        ["manifest_id", "child_manifest_id"],
        unique=True,
    )
    op.create_index("manifestchild_repository_id",
                    "manifestchild", ["repository_id"],
                    unique=False)
    op.create_index(
        "manifestchild_repository_id_child_manifest_id",
        "manifestchild",
        ["repository_id", "child_manifest_id"],
        unique=False,
    )
    op.create_index(
        "manifestchild_repository_id_manifest_id",
        "manifestchild",
        ["repository_id", "manifest_id"],
        unique=False,
    )
    op.create_index(
        "manifestchild_repository_id_manifest_id_child_manifest_id",
        "manifestchild",
        ["repository_id", "manifest_id", "child_manifest_id"],
        unique=False,
    )
    op.create_table(
        "tag",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=True),
        sa.Column("lifetime_start_ms", sa.BigInteger(), nullable=False),
        sa.Column("lifetime_end_ms", sa.BigInteger(), nullable=True),
        sa.Column("hidden",
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.expression.false()),
        sa.Column("reversion",
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.expression.false()),
        sa.Column("tag_kind_id", sa.Integer(), nullable=False),
        sa.Column("linked_tag_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["linked_tag_id"], ["tag.id"],
                                name=op.f("fk_tag_linked_tag_id_tag")),
        sa.ForeignKeyConstraint(["manifest_id"], ["manifest.id"],
                                name=op.f("fk_tag_manifest_id_manifest")),
        sa.ForeignKeyConstraint(["repository_id"], ["repository.id"],
                                name=op.f("fk_tag_repository_id_repository")),
        sa.ForeignKeyConstraint(["tag_kind_id"], ["tagkind.id"],
                                name=op.f("fk_tag_tag_kind_id_tagkind")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_tag")),
    )
    op.create_index("tag_lifetime_end_ms",
                    "tag", ["lifetime_end_ms"],
                    unique=False)
    op.create_index("tag_linked_tag_id",
                    "tag", ["linked_tag_id"],
                    unique=False)
    op.create_index("tag_manifest_id", "tag", ["manifest_id"], unique=False)
    op.create_index("tag_repository_id",
                    "tag", ["repository_id"],
                    unique=False)
    op.create_index("tag_repository_id_name",
                    "tag", ["repository_id", "name"],
                    unique=False)
    op.create_index("tag_repository_id_name_hidden",
                    "tag", ["repository_id", "name", "hidden"],
                    unique=False)
    op.create_index(
        "tag_repository_id_name_lifetime_end_ms",
        "tag",
        ["repository_id", "name", "lifetime_end_ms"],
        unique=True,
    )
    op.create_index(
        "tag_repository_id_name_tag_kind_id",
        "tag",
        ["repository_id", "name", "tag_kind_id"],
        unique=False,
    )
    op.create_index("tag_tag_kind_id", "tag", ["tag_kind_id"], unique=False)
    # ### end Alembic commands ###

    op.bulk_insert(tables.tagkind, [
        {
            "name": "tag"
        },
    ])

    # ### population of test data ### #
    tester.populate_table(
        "tag",
        [
            ("repository_id", tester.TestDataType.Foreign("repository")),
            ("tag_kind_id", tester.TestDataType.Foreign("tagkind")),
            ("name", tester.TestDataType.String),
            ("manifest_id", tester.TestDataType.Foreign("manifest")),
            ("lifetime_start_ms", tester.TestDataType.BigInteger),
        ],
    )

    tester.populate_table(
        "manifestchild",
        [
            ("repository_id", tester.TestDataType.Foreign("repository")),
            ("manifest_id", tester.TestDataType.Foreign("manifest")),
            ("child_manifest_id", tester.TestDataType.Foreign("manifest")),
        ],
    )
def downgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tagkind', sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(length=255), nullable=False),
                    sa.PrimaryKeyConstraint('id', name=op.f('pk_tagkind')))
    op.create_index('tagkind_name', 'tagkind', ['name'], unique=True)

    op.create_table(
        'blobplacementlocation', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_blobplacementlocation')))
    op.create_index('blobplacementlocation_name',
                    'blobplacementlocation', ['name'],
                    unique=True)

    op.create_table(
        'blob', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('digest', sa.String(length=255), nullable=False),
        sa.Column('media_type_id', sa.Integer(), nullable=False),
        sa.Column('size', sa.BigInteger(), nullable=False),
        sa.Column('uncompressed_size', sa.BigInteger(), nullable=True),
        sa.ForeignKeyConstraint(['media_type_id'], ['mediatype.id'],
                                name=op.f('fk_blob_media_type_id_mediatype')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_blob')))
    op.create_index('blob_digest', 'blob', ['digest'], unique=True)
    op.create_index('blob_media_type_id',
                    'blob', ['media_type_id'],
                    unique=False)

    op.create_table(
        'manifest', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('digest', sa.String(length=255), nullable=False),
        sa.Column('media_type_id', sa.Integer(), nullable=False),
        sa.Column('manifest_json', UTF8LongText, nullable=False),
        sa.ForeignKeyConstraint(
            ['media_type_id'], ['mediatype.id'],
            name=op.f('fk_manifest_media_type_id_mediatype')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_manifest')))
    op.create_index('manifest_digest', 'manifest', ['digest'], unique=True)
    op.create_index('manifest_media_type_id',
                    'manifest', ['media_type_id'],
                    unique=False)

    op.create_table(
        'manifestlist', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('digest', sa.String(length=255), nullable=False),
        sa.Column('manifest_list_json', UTF8LongText, nullable=False),
        sa.Column('schema_version', UTF8CharField(length=255), nullable=False),
        sa.Column('media_type_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['media_type_id'], ['mediatype.id'],
            name=op.f('fk_manifestlist_media_type_id_mediatype')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlist')))
    op.create_index('manifestlist_digest',
                    'manifestlist', ['digest'],
                    unique=True)
    op.create_index('manifestlist_media_type_id',
                    'manifestlist', ['media_type_id'],
                    unique=False)

    op.create_table(
        'blobplacement', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('blob_id', sa.Integer(), nullable=False),
        sa.Column('location_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['blob_id'], ['blob.id'],
                                name=op.f('fk_blobplacement_blob_id_blob')),
        sa.ForeignKeyConstraint(
            ['location_id'], ['blobplacementlocation.id'],
            name=op.f('fk_blobplacement_location_id_blobplacementlocation')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_blobplacement')))
    op.create_index('blobplacement_blob_id',
                    'blobplacement', ['blob_id'],
                    unique=False)
    op.create_index('blobplacement_blob_id_location_id',
                    'blobplacement', ['blob_id', 'location_id'],
                    unique=True)
    op.create_index('blobplacement_location_id',
                    'blobplacement', ['location_id'],
                    unique=False)

    op.create_table(
        'manifestblob', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('manifest_id', sa.Integer(), nullable=False),
        sa.Column('blob_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['blob_id'], ['blob.id'],
                                name=op.f('fk_manifestblob_blob_id_blob')),
        sa.ForeignKeyConstraint(
            ['manifest_id'], ['manifest.id'],
            name=op.f('fk_manifestblob_manifest_id_manifest')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestblob')))
    op.create_index('manifestblob_blob_id',
                    'manifestblob', ['blob_id'],
                    unique=False)
    op.create_index('manifestblob_manifest_id',
                    'manifestblob', ['manifest_id'],
                    unique=False)
    op.create_index('manifestblob_manifest_id_blob_id',
                    'manifestblob', ['manifest_id', 'blob_id'],
                    unique=True)

    op.create_table(
        'manifestlistmanifest', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('manifest_list_id', sa.Integer(), nullable=False),
        sa.Column('manifest_id', sa.Integer(), nullable=False),
        sa.Column('operating_system', UTF8CharField(length=255),
                  nullable=True),
        sa.Column('architecture', UTF8CharField(length=255), nullable=True),
        sa.Column('platform_json', UTF8LongText, nullable=True),
        sa.Column('media_type_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['manifest_id'], ['manifest.id'],
            name=op.f('fk_manifestlistmanifest_manifest_id_manifest')),
        sa.ForeignKeyConstraint(
            ['manifest_list_id'], ['manifestlist.id'],
            name=op.f(
                'fk_manifestlistmanifest_manifest_list_id_manifestlist')),
        sa.ForeignKeyConstraint(
            ['media_type_id'], ['mediatype.id'],
            name=op.f('fk_manifestlistmanifest_media_type_id_mediatype')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlistmanifest')))
    op.create_index('manifestlistmanifest_manifest_id',
                    'manifestlistmanifest', ['manifest_id'],
                    unique=False)
    op.create_index('manifestlistmanifest_manifest_list_id',
                    'manifestlistmanifest', ['manifest_list_id'],
                    unique=False)
    op.create_index('manifestlistmanifest_manifest_listid_os_arch_mtid',
                    'manifestlistmanifest', [
                        'manifest_list_id', 'operating_system', 'architecture',
                        'media_type_id'
                    ],
                    unique=False)
    op.create_index('manifestlistmanifest_manifest_listid_mtid',
                    'manifestlistmanifest',
                    ['manifest_list_id', 'media_type_id'],
                    unique=False)
    op.create_index('manifestlistmanifest_media_type_id',
                    'manifestlistmanifest', ['media_type_id'],
                    unique=False)

    op.create_table(
        'tag', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', UTF8CharField(length=190), nullable=False),
        sa.Column('repository_id', sa.Integer(), nullable=False),
        sa.Column('manifest_list_id', sa.Integer(), nullable=True),
        sa.Column('lifetime_start', sa.BigInteger(), nullable=False),
        sa.Column('lifetime_end', sa.BigInteger(), nullable=True),
        sa.Column('hidden', sa.Boolean(), nullable=False),
        sa.Column('reverted', sa.Boolean(), nullable=False),
        sa.Column('protected', sa.Boolean(), nullable=False),
        sa.Column('tag_kind_id', sa.Integer(), nullable=False),
        sa.Column('linked_tag_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['linked_tag_id'], ['tag.id'],
                                name=op.f('fk_tag_linked_tag_id_tag')),
        sa.ForeignKeyConstraint(
            ['manifest_list_id'], ['manifestlist.id'],
            name=op.f('fk_tag_manifest_list_id_manifestlist')),
        sa.ForeignKeyConstraint(['repository_id'], ['repository.id'],
                                name=op.f('fk_tag_repository_id_repository')),
        sa.ForeignKeyConstraint(['tag_kind_id'], ['tagkind.id'],
                                name=op.f('fk_tag_tag_kind_id_tagkind')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tag')))
    op.create_index('tag_lifetime_end', 'tag', ['lifetime_end'], unique=False)
    op.create_index('tag_linked_tag_id',
                    'tag', ['linked_tag_id'],
                    unique=False)
    op.create_index('tag_manifest_list_id',
                    'tag', ['manifest_list_id'],
                    unique=False)
    op.create_index('tag_repository_id',
                    'tag', ['repository_id'],
                    unique=False)
    op.create_index('tag_repository_id_name_hidden',
                    'tag', ['repository_id', 'name', 'hidden'],
                    unique=False)
    op.create_index('tag_repository_id_name_lifetime_end',
                    'tag', ['repository_id', 'name', 'lifetime_end'],
                    unique=True)
    op.create_index('tag_repository_id_name',
                    'tag', ['repository_id', 'name'],
                    unique=False)
    op.create_index('tag_tag_kind_id', 'tag', ['tag_kind_id'], unique=False)

    # ### end Alembic commands ###

    blobplacementlocation_table = table(
        'blobplacementlocation',
        column('id', sa.Integer()),
        column('name', sa.String()),
    )

    op.bulk_insert(
        blobplacementlocation_table,
        [
            {
                'name': 'local_eu'
            },
            {
                'name': 'local_us'
            },
        ],
    )

    tagkind_table = table(
        'tagkind',
        column('id', sa.Integer()),
        column('name', sa.String()),
    )

    op.bulk_insert(tagkind_table, [
        {
            'id': 1,
            'name': 'tag'
        },
        {
            'id': 2,
            'name': 'release'
        },
        {
            'id': 3,
            'name': 'channel'
        },
    ])
Esempio n. 24
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "manifest",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("digest", sa.String(length=255), nullable=False),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.Column("manifest_bytes", sa.Text(), nullable=False),
        sa.ForeignKeyConstraint(
            ["media_type_id"], ["mediatype.id"],
            name=op.f("fk_manifest_media_type_id_mediatype")),
        sa.ForeignKeyConstraint(
            ["repository_id"], ["repository.id"],
            name=op.f("fk_manifest_repository_id_repository")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifest")),
    )
    op.create_index("manifest_digest", "manifest", ["digest"], unique=False)
    op.create_index("manifest_media_type_id",
                    "manifest", ["media_type_id"],
                    unique=False)
    op.create_index("manifest_repository_id",
                    "manifest", ["repository_id"],
                    unique=False)
    op.create_index("manifest_repository_id_digest",
                    "manifest", ["repository_id", "digest"],
                    unique=True)
    op.create_index(
        "manifest_repository_id_media_type_id",
        "manifest",
        ["repository_id", "media_type_id"],
        unique=False,
    )
    op.create_table(
        "manifestblob",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("blob_id", sa.Integer(), nullable=False),
        sa.Column("blob_index", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["blob_id"], ["imagestorage.id"],
            name=op.f("fk_manifestblob_blob_id_imagestorage")),
        sa.ForeignKeyConstraint(
            ["manifest_id"], ["manifest.id"],
            name=op.f("fk_manifestblob_manifest_id_manifest")),
        sa.ForeignKeyConstraint(
            ["repository_id"],
            ["repository.id"],
            name=op.f("fk_manifestblob_repository_id_repository"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestblob")),
    )
    op.create_index("manifestblob_blob_id",
                    "manifestblob", ["blob_id"],
                    unique=False)
    op.create_index("manifestblob_manifest_id",
                    "manifestblob", ["manifest_id"],
                    unique=False)
    op.create_index("manifestblob_manifest_id_blob_id",
                    "manifestblob", ["manifest_id", "blob_id"],
                    unique=True)
    op.create_index(
        "manifestblob_manifest_id_blob_index",
        "manifestblob",
        ["manifest_id", "blob_index"],
        unique=True,
    )
    op.create_index("manifestblob_repository_id",
                    "manifestblob", ["repository_id"],
                    unique=False)
    op.create_table(
        "manifestlabel",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("label_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["label_id"], ["label.id"],
                                name=op.f("fk_manifestlabel_label_id_label")),
        sa.ForeignKeyConstraint(
            ["manifest_id"], ["manifest.id"],
            name=op.f("fk_manifestlabel_manifest_id_manifest")),
        sa.ForeignKeyConstraint(
            ["repository_id"],
            ["repository.id"],
            name=op.f("fk_manifestlabel_repository_id_repository"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlabel")),
    )
    op.create_index("manifestlabel_label_id",
                    "manifestlabel", ["label_id"],
                    unique=False)
    op.create_index("manifestlabel_manifest_id",
                    "manifestlabel", ["manifest_id"],
                    unique=False)
    op.create_index(
        "manifestlabel_manifest_id_label_id",
        "manifestlabel",
        ["manifest_id", "label_id"],
        unique=True,
    )
    op.create_index("manifestlabel_repository_id",
                    "manifestlabel", ["repository_id"],
                    unique=False)
    op.create_table(
        "manifestlegacyimage",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("image_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["image_id"], ["image.id"],
            name=op.f("fk_manifestlegacyimage_image_id_image")),
        sa.ForeignKeyConstraint(
            ["manifest_id"],
            ["manifest.id"],
            name=op.f("fk_manifestlegacyimage_manifest_id_manifest"),
        ),
        sa.ForeignKeyConstraint(
            ["repository_id"],
            ["repository.id"],
            name=op.f("fk_manifestlegacyimage_repository_id_repository"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlegacyimage")),
    )
    op.create_index("manifestlegacyimage_image_id",
                    "manifestlegacyimage", ["image_id"],
                    unique=False)
    op.create_index("manifestlegacyimage_manifest_id",
                    "manifestlegacyimage", ["manifest_id"],
                    unique=True)
    op.create_index("manifestlegacyimage_repository_id",
                    "manifestlegacyimage", ["repository_id"],
                    unique=False)
    op.create_table(
        "tagmanifesttomanifest",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tag_manifest_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("broken",
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.expression.false()),
        sa.ForeignKeyConstraint(
            ["manifest_id"],
            ["manifest.id"],
            name=op.f("fk_tagmanifesttomanifest_manifest_id_manifest"),
        ),
        sa.ForeignKeyConstraint(
            ["tag_manifest_id"],
            ["tagmanifest.id"],
            name=op.f("fk_tagmanifesttomanifest_tag_manifest_id_tagmanifest"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_tagmanifesttomanifest")),
    )
    op.create_index("tagmanifesttomanifest_broken",
                    "tagmanifesttomanifest", ["broken"],
                    unique=False)
    op.create_index("tagmanifesttomanifest_manifest_id",
                    "tagmanifesttomanifest", ["manifest_id"],
                    unique=True)
    op.create_index(
        "tagmanifesttomanifest_tag_manifest_id",
        "tagmanifesttomanifest",
        ["tag_manifest_id"],
        unique=True,
    )
    op.create_table(
        "tagmanifestlabelmap",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tag_manifest_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=True),
        sa.Column("label_id", sa.Integer(), nullable=False),
        sa.Column("tag_manifest_label_id", sa.Integer(), nullable=False),
        sa.Column("manifest_label_id", sa.Integer(), nullable=True),
        sa.Column(
            "broken_manifest",
            sa.Boolean(),
            nullable=False,
            server_default=sa.sql.expression.false(),
        ),
        sa.ForeignKeyConstraint(
            ["label_id"], ["label.id"],
            name=op.f("fk_tagmanifestlabelmap_label_id_label")),
        sa.ForeignKeyConstraint(
            ["manifest_id"],
            ["manifest.id"],
            name=op.f("fk_tagmanifestlabelmap_manifest_id_manifest"),
        ),
        sa.ForeignKeyConstraint(
            ["manifest_label_id"],
            ["manifestlabel.id"],
            name=op.f(
                "fk_tagmanifestlabelmap_manifest_label_id_manifestlabel"),
        ),
        sa.ForeignKeyConstraint(
            ["tag_manifest_id"],
            ["tagmanifest.id"],
            name=op.f("fk_tagmanifestlabelmap_tag_manifest_id_tagmanifest"),
        ),
        sa.ForeignKeyConstraint(
            ["tag_manifest_label_id"],
            ["tagmanifestlabel.id"],
            name=op.
            f("fk_tagmanifestlabelmap_tag_manifest_label_id_tagmanifestlabel"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_tagmanifestlabelmap")),
    )
    op.create_index(
        "tagmanifestlabelmap_broken_manifest",
        "tagmanifestlabelmap",
        ["broken_manifest"],
        unique=False,
    )
    op.create_index("tagmanifestlabelmap_label_id",
                    "tagmanifestlabelmap", ["label_id"],
                    unique=False)
    op.create_index("tagmanifestlabelmap_manifest_id",
                    "tagmanifestlabelmap", ["manifest_id"],
                    unique=False)
    op.create_index(
        "tagmanifestlabelmap_manifest_label_id",
        "tagmanifestlabelmap",
        ["manifest_label_id"],
        unique=False,
    )
    op.create_index(
        "tagmanifestlabelmap_tag_manifest_id",
        "tagmanifestlabelmap",
        ["tag_manifest_id"],
        unique=False,
    )
    op.create_index(
        "tagmanifestlabelmap_tag_manifest_label_id",
        "tagmanifestlabelmap",
        ["tag_manifest_label_id"],
        unique=False,
    )
    # ### end Alembic commands ###

    for media_type in DOCKER_SCHEMA1_CONTENT_TYPES:
        op.bulk_insert(tables.mediatype, [
            {
                "name": media_type
            },
        ])

    # ### population of test data ### #
    tester.populate_table(
        "manifest",
        [
            ("digest", tester.TestDataType.String),
            ("manifest_bytes", tester.TestDataType.JSON),
            ("media_type_id", tester.TestDataType.Foreign("mediatype")),
            ("repository_id", tester.TestDataType.Foreign("repository")),
        ],
    )

    tester.populate_table(
        "manifestblob",
        [
            ("manifest_id", tester.TestDataType.Foreign("manifest")),
            ("repository_id", tester.TestDataType.Foreign("repository")),
            ("blob_id", tester.TestDataType.Foreign("imagestorage")),
            ("blob_index", tester.TestDataType.Integer),
        ],
    )

    tester.populate_table(
        "manifestlabel",
        [
            ("manifest_id", tester.TestDataType.Foreign("manifest")),
            ("label_id", tester.TestDataType.Foreign("label")),
            ("repository_id", tester.TestDataType.Foreign("repository")),
        ],
    )

    tester.populate_table(
        "manifestlegacyimage",
        [
            ("manifest_id", tester.TestDataType.Foreign("manifest")),
            ("image_id", tester.TestDataType.Foreign("image")),
            ("repository_id", tester.TestDataType.Foreign("repository")),
        ],
    )

    tester.populate_table(
        "tagmanifesttomanifest",
        [
            ("manifest_id", tester.TestDataType.Foreign("manifest")),
            ("tag_manifest_id", tester.TestDataType.Foreign("tagmanifest")),
        ],
    )

    tester.populate_table(
        "tagmanifestlabelmap",
        [
            ("manifest_id", tester.TestDataType.Foreign("manifest")),
            ("tag_manifest_id", tester.TestDataType.Foreign("tagmanifest")),
            ("tag_manifest_label_id",
             tester.TestDataType.Foreign("tagmanifestlabel")),
            ("manifest_label_id",
             tester.TestDataType.Foreign("manifestlabel")),
            ("label_id", tester.TestDataType.Foreign("label")),
        ],
    )
Esempio n. 25
0
def upgrade(tables, tester, progress_reporter):
  op = ProgressWrapper(original_op, progress_reporter)
  op.create_table('repomirrorrule',
  sa.Column('id', sa.Integer(), nullable=False),
  sa.Column('uuid', sa.String(length=36), nullable=False),
  sa.Column('repository_id', sa.Integer(), nullable=False),
  sa.Column('creation_date', sa.DateTime(), nullable=False),
  sa.Column('rule_type', sa.Integer(), nullable=False),
  sa.Column('rule_value', sa.Text(), nullable=False),
  sa.Column('left_child_id', sa.Integer(), nullable=True),
  sa.Column('right_child_id', sa.Integer(), nullable=True),
  sa.ForeignKeyConstraint(['left_child_id'], ['repomirrorrule.id'], name=op.f('fk_repomirrorrule_left_child_id_repomirrorrule')),
  sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], name=op.f('fk_repomirrorrule_repository_id_repository')),
  sa.ForeignKeyConstraint(['right_child_id'], ['repomirrorrule.id'], name=op.f('fk_repomirrorrule_right_child_id_repomirrorrule')),
  sa.PrimaryKeyConstraint('id', name=op.f('pk_repomirrorrule')))
  op.create_index('repomirrorrule_left_child_id', 'repomirrorrule', ['left_child_id'], unique=False)
  op.create_index('repomirrorrule_repository_id', 'repomirrorrule', ['repository_id'], unique=False)
  op.create_index('repomirrorrule_right_child_id', 'repomirrorrule', ['right_child_id'], unique=False)
  op.create_index('repomirrorrule_rule_type', 'repomirrorrule', ['rule_type'], unique=False)
  op.create_index('repomirrorrule_uuid', 'repomirrorrule', ['uuid'], unique=True)

  op.create_table('repomirrorconfig',
  sa.Column('id', sa.Integer(), nullable=False),
  sa.Column('repository_id', sa.Integer(), nullable=False),
  sa.Column('creation_date', sa.DateTime(), nullable=False),
  sa.Column('is_enabled', sa.Boolean(), nullable=False),
  sa.Column('mirror_type', sa.Integer(), nullable=False),
  sa.Column('internal_robot_id', sa.Integer(), nullable=False),
  sa.Column('external_registry', sa.String(length=255), nullable=False),
  sa.Column('external_namespace', sa.String(length=255), nullable=False),
  sa.Column('external_repository', sa.String(length=255), nullable=False),
  sa.Column('external_registry_username', sa.String(length=2048), nullable=True),
  sa.Column('external_registry_password', sa.String(length=2048), nullable=True),
  sa.Column('external_registry_config', sa.Text(), nullable=False),
  sa.Column('sync_interval', sa.Integer(), nullable=False, server_default='60'),
  sa.Column('sync_start_date', sa.DateTime(), nullable=True),
  sa.Column('sync_expiration_date', sa.DateTime(), nullable=True),
  sa.Column('sync_retries_remaining', sa.Integer(), nullable=False, server_default='3'),
  sa.Column('sync_status', sa.Integer(), nullable=False),
  sa.Column('sync_transaction_id', sa.String(length=36), nullable=True),
  sa.Column('root_rule_id', sa.Integer(), nullable=False),
  sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], name=op.f('fk_repomirrorconfig_repository_id_repository')),
  sa.ForeignKeyConstraint(['root_rule_id'], ['repomirrorrule.id'], name=op.f('fk_repomirrorconfig_root_rule_id_repomirrorrule')),
  sa.ForeignKeyConstraint(['internal_robot_id'], ['user.id'], name=op.f('fk_repomirrorconfig_internal_robot_id_user')),
  sa.PrimaryKeyConstraint('id', name=op.f('pk_repomirrorconfig'))
  )
  op.create_index('repomirrorconfig_mirror_type', 'repomirrorconfig', ['mirror_type'], unique=False)
  op.create_index('repomirrorconfig_repository_id', 'repomirrorconfig', ['repository_id'], unique=True)
  op.create_index('repomirrorconfig_root_rule_id', 'repomirrorconfig', ['root_rule_id'], unique=False)
  op.create_index('repomirrorconfig_sync_status', 'repomirrorconfig', ['sync_status'], unique=False)
  op.create_index('repomirrorconfig_sync_transaction_id', 'repomirrorconfig', ['sync_transaction_id'], unique=False)
  op.create_index('repomirrorconfig_internal_robot_id', 'repomirrorconfig', ['internal_robot_id'], unique=False)

  op.add_column(u'repository', sa.Column('state', sa.Integer(), nullable=False, server_default='0'))
  op.create_index('repository_state', 'repository', ['state'], unique=False)

  op.bulk_insert(tables.logentrykind,
               [
                 {'name': 'repo_mirror_enabled'},
                 {'name': 'repo_mirror_disabled'},
                 {'name': 'repo_mirror_config_changed'},
                 {'name': 'repo_mirror_sync_started'},
                 {'name': 'repo_mirror_sync_failed'},
                 {'name': 'repo_mirror_sync_success'},
                 {'name': 'repo_mirror_sync_now_requested'},
                 {'name': 'repo_mirror_sync_tag_success'},
                 {'name': 'repo_mirror_sync_tag_failed'},
                 {'name': 'repo_mirror_sync_test_success'},
                 {'name': 'repo_mirror_sync_test_failed'},
                 {'name': 'repo_mirror_sync_test_started'},
                 {'name': 'change_repo_state'}
               ])


  tester.populate_table('repomirrorrule', [
    ('uuid', tester.TestDataType.String),
    ('repository_id', tester.TestDataType.Foreign('repository')),
    ('creation_date', tester.TestDataType.DateTime),
    ('rule_type', tester.TestDataType.Integer),
    ('rule_value', tester.TestDataType.String),
  ])

  tester.populate_table('repomirrorconfig', [
    ('repository_id', tester.TestDataType.Foreign('repository')),
    ('creation_date', tester.TestDataType.DateTime),
    ('is_enabled', tester.TestDataType.Boolean),
    ('mirror_type', tester.TestDataType.Constant(1)),
    ('internal_robot_id', tester.TestDataType.Foreign('user')),
    ('external_registry', tester.TestDataType.String),
    ('external_namespace', tester.TestDataType.String),
    ('external_repository', tester.TestDataType.String),
    ('external_registry_username', tester.TestDataType.String),
    ('external_registry_password', tester.TestDataType.String),
    ('external_registry_config', tester.TestDataType.JSON),
    ('sync_start_date', tester.TestDataType.DateTime),
    ('sync_expiration_date', tester.TestDataType.DateTime),
    ('sync_retries_remaining', tester.TestDataType.Integer),
    ('sync_status', tester.TestDataType.Constant(0)),
    ('sync_transaction_id', tester.TestDataType.String),
    ('root_rule_id', tester.TestDataType.Foreign('repomirrorrule')),
  ])
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tagkind', sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(length=255), nullable=False),
                    sa.PrimaryKeyConstraint('id', name=op.f('pk_tagkind')))
    op.create_index('tagkind_name', 'tagkind', ['name'], unique=True)
    op.create_table(
        'manifestchild', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('repository_id', sa.Integer(), nullable=False),
        sa.Column('manifest_id', sa.Integer(), nullable=False),
        sa.Column('child_manifest_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['child_manifest_id'], ['manifest.id'],
            name=op.f('fk_manifestchild_child_manifest_id_manifest')),
        sa.ForeignKeyConstraint(
            ['manifest_id'], ['manifest.id'],
            name=op.f('fk_manifestchild_manifest_id_manifest')),
        sa.ForeignKeyConstraint(
            ['repository_id'], ['repository.id'],
            name=op.f('fk_manifestchild_repository_id_repository')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestchild')))
    op.create_index('manifestchild_child_manifest_id',
                    'manifestchild', ['child_manifest_id'],
                    unique=False)
    op.create_index('manifestchild_manifest_id',
                    'manifestchild', ['manifest_id'],
                    unique=False)
    op.create_index('manifestchild_manifest_id_child_manifest_id',
                    'manifestchild', ['manifest_id', 'child_manifest_id'],
                    unique=True)
    op.create_index('manifestchild_repository_id',
                    'manifestchild', ['repository_id'],
                    unique=False)
    op.create_index('manifestchild_repository_id_child_manifest_id',
                    'manifestchild', ['repository_id', 'child_manifest_id'],
                    unique=False)
    op.create_index('manifestchild_repository_id_manifest_id',
                    'manifestchild', ['repository_id', 'manifest_id'],
                    unique=False)
    op.create_index(
        'manifestchild_repository_id_manifest_id_child_manifest_id',
        'manifestchild', ['repository_id', 'manifest_id', 'child_manifest_id'],
        unique=False)
    op.create_table(
        'tag', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=False),
        sa.Column('repository_id', sa.Integer(), nullable=False),
        sa.Column('manifest_id', sa.Integer(), nullable=True),
        sa.Column('lifetime_start_ms', sa.BigInteger(), nullable=False),
        sa.Column('lifetime_end_ms', sa.BigInteger(), nullable=True),
        sa.Column('hidden',
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.expression.false()),
        sa.Column('reversion',
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.expression.false()),
        sa.Column('tag_kind_id', sa.Integer(), nullable=False),
        sa.Column('linked_tag_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['linked_tag_id'], ['tag.id'],
                                name=op.f('fk_tag_linked_tag_id_tag')),
        sa.ForeignKeyConstraint(['manifest_id'], ['manifest.id'],
                                name=op.f('fk_tag_manifest_id_manifest')),
        sa.ForeignKeyConstraint(['repository_id'], ['repository.id'],
                                name=op.f('fk_tag_repository_id_repository')),
        sa.ForeignKeyConstraint(['tag_kind_id'], ['tagkind.id'],
                                name=op.f('fk_tag_tag_kind_id_tagkind')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tag')))
    op.create_index('tag_lifetime_end_ms',
                    'tag', ['lifetime_end_ms'],
                    unique=False)
    op.create_index('tag_linked_tag_id',
                    'tag', ['linked_tag_id'],
                    unique=False)
    op.create_index('tag_manifest_id', 'tag', ['manifest_id'], unique=False)
    op.create_index('tag_repository_id',
                    'tag', ['repository_id'],
                    unique=False)
    op.create_index('tag_repository_id_name',
                    'tag', ['repository_id', 'name'],
                    unique=False)
    op.create_index('tag_repository_id_name_hidden',
                    'tag', ['repository_id', 'name', 'hidden'],
                    unique=False)
    op.create_index('tag_repository_id_name_lifetime_end_ms',
                    'tag', ['repository_id', 'name', 'lifetime_end_ms'],
                    unique=True)
    op.create_index('tag_repository_id_name_tag_kind_id',
                    'tag', ['repository_id', 'name', 'tag_kind_id'],
                    unique=False)
    op.create_index('tag_tag_kind_id', 'tag', ['tag_kind_id'], unique=False)
    # ### end Alembic commands ###

    op.bulk_insert(tables.tagkind, [
        {
            'name': 'tag'
        },
    ])

    # ### population of test data ### #
    tester.populate_table('tag', [
        ('repository_id', tester.TestDataType.Foreign('repository')),
        ('tag_kind_id', tester.TestDataType.Foreign('tagkind')),
        ('name', tester.TestDataType.String),
        ('manifest_id', tester.TestDataType.Foreign('manifest')),
        ('lifetime_start_ms', tester.TestDataType.BigInteger),
    ])

    tester.populate_table('manifestchild', [
        ('repository_id', tester.TestDataType.Foreign('repository')),
        ('manifest_id', tester.TestDataType.Foreign('manifest')),
        ('child_manifest_id', tester.TestDataType.Foreign('manifest')),
    ])
Esempio n. 27
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    op.create_table(
        "tagkind",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_tagkind")),
    )
    op.create_index("tagkind_name", "tagkind", ["name"], unique=True)

    op.create_table(
        "blobplacementlocation",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_blobplacementlocation")),
    )
    op.create_index("blobplacementlocation_name",
                    "blobplacementlocation", ["name"],
                    unique=True)

    op.create_table(
        "blob",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("digest", sa.String(length=255), nullable=False),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.Column("size", sa.BigInteger(), nullable=False),
        sa.Column("uncompressed_size", sa.BigInteger(), nullable=True),
        sa.ForeignKeyConstraint(["media_type_id"], ["mediatype.id"],
                                name=op.f("fk_blob_media_type_id_mediatype")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_blob")),
    )
    op.create_index("blob_digest", "blob", ["digest"], unique=True)
    op.create_index("blob_media_type_id",
                    "blob", ["media_type_id"],
                    unique=False)

    op.create_table(
        "blobplacementlocationpreference",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("location_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["location_id"],
            ["blobplacementlocation.id"],
            name=op.f("fk_blobplacementlocpref_locid_blobplacementlocation"),
        ),
        sa.ForeignKeyConstraint(
            ["user_id"], ["user.id"],
            name=op.f("fk_blobplacementlocationpreference_user_id_user")),
        sa.PrimaryKeyConstraint(
            "id", name=op.f("pk_blobplacementlocationpreference")),
    )
    op.create_index(
        "blobplacementlocationpreference_location_id",
        "blobplacementlocationpreference",
        ["location_id"],
        unique=False,
    )
    op.create_index(
        "blobplacementlocationpreference_user_id",
        "blobplacementlocationpreference",
        ["user_id"],
        unique=False,
    )

    op.create_table(
        "manifest",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("digest", sa.String(length=255), nullable=False),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.Column("manifest_json", UTF8LongText, nullable=False),
        sa.ForeignKeyConstraint(
            ["media_type_id"], ["mediatype.id"],
            name=op.f("fk_manifest_media_type_id_mediatype")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifest")),
    )
    op.create_index("manifest_digest", "manifest", ["digest"], unique=True)
    op.create_index("manifest_media_type_id",
                    "manifest", ["media_type_id"],
                    unique=False)

    op.create_table(
        "manifestlist",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("digest", sa.String(length=255), nullable=False),
        sa.Column("manifest_list_json", UTF8LongText, nullable=False),
        sa.Column("schema_version", UTF8CharField(length=255), nullable=False),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["media_type_id"],
            ["mediatype.id"],
            name=op.f("fk_manifestlist_media_type_id_mediatype"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlist")),
    )
    op.create_index("manifestlist_digest",
                    "manifestlist", ["digest"],
                    unique=True)
    op.create_index("manifestlist_media_type_id",
                    "manifestlist", ["media_type_id"],
                    unique=False)

    op.create_table(
        "bittorrentpieces",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("blob_id", sa.Integer(), nullable=False),
        sa.Column("pieces", UTF8LongText, nullable=False),
        sa.Column("piece_length", sa.BigInteger(), nullable=False),
        sa.ForeignKeyConstraint(["blob_id"], ["blob.id"],
                                name=op.f("fk_bittorrentpieces_blob_id_blob")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_bittorrentpieces")),
    )
    op.create_index("bittorrentpieces_blob_id",
                    "bittorrentpieces", ["blob_id"],
                    unique=False)
    op.create_index(
        "bittorrentpieces_blob_id_piece_length",
        "bittorrentpieces",
        ["blob_id", "piece_length"],
        unique=True,
    )

    op.create_table(
        "blobplacement",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("blob_id", sa.Integer(), nullable=False),
        sa.Column("location_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["blob_id"], ["blob.id"],
                                name=op.f("fk_blobplacement_blob_id_blob")),
        sa.ForeignKeyConstraint(
            ["location_id"],
            ["blobplacementlocation.id"],
            name=op.f("fk_blobplacement_location_id_blobplacementlocation"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_blobplacement")),
    )
    op.create_index("blobplacement_blob_id",
                    "blobplacement", ["blob_id"],
                    unique=False)
    op.create_index(
        "blobplacement_blob_id_location_id",
        "blobplacement",
        ["blob_id", "location_id"],
        unique=True,
    )
    op.create_index("blobplacement_location_id",
                    "blobplacement", ["location_id"],
                    unique=False)

    op.create_table(
        "blobuploading",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("uuid", sa.String(length=255), nullable=False),
        sa.Column("created", sa.DateTime(), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("location_id", sa.Integer(), nullable=False),
        sa.Column("byte_count", sa.BigInteger(), nullable=False),
        sa.Column("uncompressed_byte_count", sa.BigInteger(), nullable=True),
        sa.Column("chunk_count", sa.BigInteger(), nullable=False),
        sa.Column("storage_metadata", UTF8LongText, nullable=True),
        sa.Column("sha_state", UTF8LongText, nullable=True),
        sa.Column("piece_sha_state", UTF8LongText, nullable=True),
        sa.Column("piece_hashes", UTF8LongText, nullable=True),
        sa.ForeignKeyConstraint(
            ["location_id"],
            ["blobplacementlocation.id"],
            name=op.f("fk_blobuploading_location_id_blobplacementlocation"),
        ),
        sa.ForeignKeyConstraint(
            ["repository_id"],
            ["repository.id"],
            name=op.f("fk_blobuploading_repository_id_repository"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_blobuploading")),
    )
    op.create_index("blobuploading_created",
                    "blobuploading", ["created"],
                    unique=False)
    op.create_index("blobuploading_location_id",
                    "blobuploading", ["location_id"],
                    unique=False)
    op.create_index("blobuploading_repository_id",
                    "blobuploading", ["repository_id"],
                    unique=False)
    op.create_index("blobuploading_repository_id_uuid",
                    "blobuploading", ["repository_id", "uuid"],
                    unique=True)
    op.create_index("blobuploading_uuid",
                    "blobuploading", ["uuid"],
                    unique=True)

    op.create_table(
        "derivedimage",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("uuid", sa.String(length=255), nullable=False),
        sa.Column("source_manifest_id", sa.Integer(), nullable=False),
        sa.Column("derived_manifest_json", UTF8LongText, nullable=False),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.Column("blob_id", sa.Integer(), nullable=False),
        sa.Column("uniqueness_hash", sa.String(length=255), nullable=False),
        sa.Column("signature_blob_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["blob_id"], ["blob.id"],
                                name=op.f("fk_derivedimage_blob_id_blob")),
        sa.ForeignKeyConstraint(
            ["media_type_id"],
            ["mediatype.id"],
            name=op.f("fk_derivedimage_media_type_id_mediatype"),
        ),
        sa.ForeignKeyConstraint(
            ["signature_blob_id"], ["blob.id"],
            name=op.f("fk_derivedimage_signature_blob_id_blob")),
        sa.ForeignKeyConstraint(
            ["source_manifest_id"],
            ["manifest.id"],
            name=op.f("fk_derivedimage_source_manifest_id_manifest"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_derivedimage")),
    )
    op.create_index("derivedimage_blob_id",
                    "derivedimage", ["blob_id"],
                    unique=False)
    op.create_index("derivedimage_media_type_id",
                    "derivedimage", ["media_type_id"],
                    unique=False)
    op.create_index("derivedimage_signature_blob_id",
                    "derivedimage", ["signature_blob_id"],
                    unique=False)
    op.create_index("derivedimage_source_manifest_id",
                    "derivedimage", ["source_manifest_id"],
                    unique=False)
    op.create_index(
        "derivedimage_source_manifest_id_blob_id",
        "derivedimage",
        ["source_manifest_id", "blob_id"],
        unique=True,
    )
    op.create_index(
        "derivedimage_source_manifest_id_media_type_id_uniqueness_hash",
        "derivedimage",
        ["source_manifest_id", "media_type_id", "uniqueness_hash"],
        unique=True,
    )
    op.create_index("derivedimage_uniqueness_hash",
                    "derivedimage", ["uniqueness_hash"],
                    unique=True)
    op.create_index("derivedimage_uuid", "derivedimage", ["uuid"], unique=True)

    op.create_table(
        "manifestblob",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("blob_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["blob_id"], ["blob.id"],
                                name=op.f("fk_manifestblob_blob_id_blob")),
        sa.ForeignKeyConstraint(
            ["manifest_id"], ["manifest.id"],
            name=op.f("fk_manifestblob_manifest_id_manifest")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestblob")),
    )
    op.create_index("manifestblob_blob_id",
                    "manifestblob", ["blob_id"],
                    unique=False)
    op.create_index("manifestblob_manifest_id",
                    "manifestblob", ["manifest_id"],
                    unique=False)
    op.create_index("manifestblob_manifest_id_blob_id",
                    "manifestblob", ["manifest_id", "blob_id"],
                    unique=True)

    op.create_table(
        "manifestlabel",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("annotated_id", sa.Integer(), nullable=False),
        sa.Column("label_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["annotated_id"], ["manifest.id"],
            name=op.f("fk_manifestlabel_annotated_id_manifest")),
        sa.ForeignKeyConstraint(["label_id"], ["label.id"],
                                name=op.f("fk_manifestlabel_label_id_label")),
        sa.ForeignKeyConstraint(
            ["repository_id"],
            ["repository.id"],
            name=op.f("fk_manifestlabel_repository_id_repository"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlabel")),
    )
    op.create_index("manifestlabel_annotated_id",
                    "manifestlabel", ["annotated_id"],
                    unique=False)
    op.create_index("manifestlabel_label_id",
                    "manifestlabel", ["label_id"],
                    unique=False)
    op.create_index("manifestlabel_repository_id",
                    "manifestlabel", ["repository_id"],
                    unique=False)
    op.create_index(
        "manifestlabel_repository_id_annotated_id_label_id",
        "manifestlabel",
        ["repository_id", "annotated_id", "label_id"],
        unique=True,
    )

    op.create_table(
        "manifestlayer",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("blob_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("manifest_index", sa.BigInteger(), nullable=False),
        sa.Column("metadata_json", UTF8LongText, nullable=False),
        sa.ForeignKeyConstraint(["blob_id"], ["blob.id"],
                                name=op.f("fk_manifestlayer_blob_id_blob")),
        sa.ForeignKeyConstraint(
            ["manifest_id"], ["manifest.id"],
            name=op.f("fk_manifestlayer_manifest_id_manifest")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlayer")),
    )
    op.create_index("manifestlayer_blob_id",
                    "manifestlayer", ["blob_id"],
                    unique=False)
    op.create_index("manifestlayer_manifest_id",
                    "manifestlayer", ["manifest_id"],
                    unique=False)
    op.create_index(
        "manifestlayer_manifest_id_manifest_index",
        "manifestlayer",
        ["manifest_id", "manifest_index"],
        unique=True,
    )
    op.create_index("manifestlayer_manifest_index",
                    "manifestlayer", ["manifest_index"],
                    unique=False)

    op.create_table(
        "manifestlistmanifest",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("manifest_list_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("operating_system", UTF8CharField(length=255),
                  nullable=True),
        sa.Column("architecture", UTF8CharField(length=255), nullable=True),
        sa.Column("platform_json", UTF8LongText, nullable=True),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["manifest_id"],
            ["manifest.id"],
            name=op.f("fk_manifestlistmanifest_manifest_id_manifest"),
        ),
        sa.ForeignKeyConstraint(
            ["manifest_list_id"],
            ["manifestlist.id"],
            name=op.f("fk_manifestlistmanifest_manifest_list_id_manifestlist"),
        ),
        sa.ForeignKeyConstraint(
            ["media_type_id"],
            ["mediatype.id"],
            name=op.f("fk_manifestlistmanifest_media_type_id_mediatype"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlistmanifest")),
    )
    op.create_index("manifestlistmanifest_manifest_id",
                    "manifestlistmanifest", ["manifest_id"],
                    unique=False)
    op.create_index(
        "manifestlistmanifest_manifest_list_id",
        "manifestlistmanifest",
        ["manifest_list_id"],
        unique=False,
    )
    op.create_index(
        "manifestlistmanifest_manifest_listid_os_arch_mtid",
        "manifestlistmanifest",
        [
            "manifest_list_id", "operating_system", "architecture",
            "media_type_id"
        ],
        unique=False,
    )
    op.create_index(
        "manifestlistmanifest_manifest_listid_mtid",
        "manifestlistmanifest",
        ["manifest_list_id", "media_type_id"],
        unique=False,
    )
    op.create_index(
        "manifestlistmanifest_media_type_id",
        "manifestlistmanifest",
        ["media_type_id"],
        unique=False,
    )

    op.create_table(
        "tag",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", UTF8CharField(length=190), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("manifest_list_id", sa.Integer(), nullable=True),
        sa.Column("lifetime_start", sa.BigInteger(), nullable=False),
        sa.Column("lifetime_end", sa.BigInteger(), nullable=True),
        sa.Column("hidden", sa.Boolean(), nullable=False),
        sa.Column("reverted", sa.Boolean(), nullable=False),
        sa.Column("protected", sa.Boolean(), nullable=False),
        sa.Column("tag_kind_id", sa.Integer(), nullable=False),
        sa.Column("linked_tag_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["linked_tag_id"], ["tag.id"],
                                name=op.f("fk_tag_linked_tag_id_tag")),
        sa.ForeignKeyConstraint(
            ["manifest_list_id"],
            ["manifestlist.id"],
            name=op.f("fk_tag_manifest_list_id_manifestlist"),
        ),
        sa.ForeignKeyConstraint(["repository_id"], ["repository.id"],
                                name=op.f("fk_tag_repository_id_repository")),
        sa.ForeignKeyConstraint(["tag_kind_id"], ["tagkind.id"],
                                name=op.f("fk_tag_tag_kind_id_tagkind")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_tag")),
    )
    op.create_index("tag_lifetime_end", "tag", ["lifetime_end"], unique=False)
    op.create_index("tag_linked_tag_id",
                    "tag", ["linked_tag_id"],
                    unique=False)
    op.create_index("tag_manifest_list_id",
                    "tag", ["manifest_list_id"],
                    unique=False)
    op.create_index("tag_repository_id",
                    "tag", ["repository_id"],
                    unique=False)
    op.create_index("tag_repository_id_name_hidden",
                    "tag", ["repository_id", "name", "hidden"],
                    unique=False)
    op.create_index(
        "tag_repository_id_name_lifetime_end",
        "tag",
        ["repository_id", "name", "lifetime_end"],
        unique=True,
    )
    op.create_index("tag_repository_id_name",
                    "tag", ["repository_id", "name"],
                    unique=False)
    op.create_index("tag_tag_kind_id", "tag", ["tag_kind_id"], unique=False)

    op.create_table(
        "manifestlayerdockerv1",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("manifest_layer_id", sa.Integer(), nullable=False),
        sa.Column("image_id", UTF8CharField(length=255), nullable=False),
        sa.Column("checksum", UTF8CharField(length=255), nullable=False),
        sa.Column("compat_json", UTF8LongText, nullable=False),
        sa.ForeignKeyConstraint(
            ["manifest_layer_id"],
            ["manifestlayer.id"],
            name=op.f(
                "fk_manifestlayerdockerv1_manifest_layer_id_manifestlayer"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlayerdockerv1")),
    )
    op.create_index("manifestlayerdockerv1_image_id",
                    "manifestlayerdockerv1", ["image_id"],
                    unique=False)
    op.create_index(
        "manifestlayerdockerv1_manifest_layer_id",
        "manifestlayerdockerv1",
        ["manifest_layer_id"],
        unique=False,
    )

    op.create_table(
        "manifestlayerscan",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("layer_id", sa.Integer(), nullable=False),
        sa.Column("scannable", sa.Boolean(), nullable=False),
        sa.Column("scanned_by", UTF8CharField(length=255), nullable=False),
        sa.ForeignKeyConstraint(
            ["layer_id"],
            ["manifestlayer.id"],
            name=op.f("fk_manifestlayerscan_layer_id_manifestlayer"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlayerscan")),
    )
    op.create_index("manifestlayerscan_layer_id",
                    "manifestlayerscan", ["layer_id"],
                    unique=True)

    blobplacementlocation_table = table(
        "blobplacementlocation",
        column("id", sa.Integer()),
        column("name", sa.String()),
    )

    op.bulk_insert(
        blobplacementlocation_table,
        [
            {
                "name": "local_eu"
            },
            {
                "name": "local_us"
            },
        ],
    )

    op.bulk_insert(
        tables.mediatype,
        [
            {
                "name": "application/vnd.cnr.blob.v0.tar+gzip"
            },
            {
                "name": "application/vnd.cnr.package-manifest.helm.v0.json"
            },
            {
                "name": "application/vnd.cnr.package-manifest.kpm.v0.json"
            },
            {
                "name":
                "application/vnd.cnr.package-manifest.docker-compose.v0.json"
            },
            {
                "name": "application/vnd.cnr.package.kpm.v0.tar+gzip"
            },
            {
                "name": "application/vnd.cnr.package.helm.v0.tar+gzip"
            },
            {
                "name":
                "application/vnd.cnr.package.docker-compose.v0.tar+gzip"
            },
            {
                "name": "application/vnd.cnr.manifests.v0.json"
            },
            {
                "name": "application/vnd.cnr.manifest.list.v0.json"
            },
        ],
    )

    tagkind_table = table(
        "tagkind",
        column("id", sa.Integer()),
        column("name", sa.String()),
    )

    op.bulk_insert(
        tagkind_table,
        [
            {
                "id": 1,
                "name": "tag"
            },
            {
                "id": 2,
                "name": "release"
            },
            {
                "id": 3,
                "name": "channel"
            },
        ],
    )
Esempio n. 28
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    op.create_table(
        "repomirrorrule",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("uuid", sa.String(length=36), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("creation_date", sa.DateTime(), nullable=False),
        sa.Column("rule_type", sa.Integer(), nullable=False),
        sa.Column("rule_value", sa.Text(), nullable=False),
        sa.Column("left_child_id", sa.Integer(), nullable=True),
        sa.Column("right_child_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["left_child_id"],
            ["repomirrorrule.id"],
            name=op.f("fk_repomirrorrule_left_child_id_repomirrorrule"),
        ),
        sa.ForeignKeyConstraint(
            ["repository_id"],
            ["repository.id"],
            name=op.f("fk_repomirrorrule_repository_id_repository"),
        ),
        sa.ForeignKeyConstraint(
            ["right_child_id"],
            ["repomirrorrule.id"],
            name=op.f("fk_repomirrorrule_right_child_id_repomirrorrule"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_repomirrorrule")),
    )
    op.create_index("repomirrorrule_left_child_id",
                    "repomirrorrule", ["left_child_id"],
                    unique=False)
    op.create_index("repomirrorrule_repository_id",
                    "repomirrorrule", ["repository_id"],
                    unique=False)
    op.create_index("repomirrorrule_right_child_id",
                    "repomirrorrule", ["right_child_id"],
                    unique=False)
    op.create_index("repomirrorrule_rule_type",
                    "repomirrorrule", ["rule_type"],
                    unique=False)
    op.create_index("repomirrorrule_uuid",
                    "repomirrorrule", ["uuid"],
                    unique=True)

    op.create_table(
        "repomirrorconfig",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("creation_date", sa.DateTime(), nullable=False),
        sa.Column("is_enabled", sa.Boolean(), nullable=False),
        sa.Column("mirror_type", sa.Integer(), nullable=False),
        sa.Column("internal_robot_id", sa.Integer(), nullable=False),
        sa.Column("external_registry", sa.String(length=255), nullable=False),
        sa.Column("external_namespace", sa.String(length=255), nullable=False),
        sa.Column("external_repository", sa.String(length=255),
                  nullable=False),
        sa.Column("external_registry_username",
                  sa.String(length=2048),
                  nullable=True),
        sa.Column("external_registry_password",
                  sa.String(length=2048),
                  nullable=True),
        sa.Column("external_registry_config", sa.Text(), nullable=False),
        sa.Column("sync_interval",
                  sa.Integer(),
                  nullable=False,
                  server_default="60"),
        sa.Column("sync_start_date", sa.DateTime(), nullable=True),
        sa.Column("sync_expiration_date", sa.DateTime(), nullable=True),
        sa.Column("sync_retries_remaining",
                  sa.Integer(),
                  nullable=False,
                  server_default="3"),
        sa.Column("sync_status", sa.Integer(), nullable=False),
        sa.Column("sync_transaction_id", sa.String(length=36), nullable=True),
        sa.Column("root_rule_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["repository_id"],
            ["repository.id"],
            name=op.f("fk_repomirrorconfig_repository_id_repository"),
        ),
        sa.ForeignKeyConstraint(
            ["root_rule_id"],
            ["repomirrorrule.id"],
            name=op.f("fk_repomirrorconfig_root_rule_id_repomirrorrule"),
        ),
        sa.ForeignKeyConstraint(
            ["internal_robot_id"],
            ["user.id"],
            name=op.f("fk_repomirrorconfig_internal_robot_id_user"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_repomirrorconfig")),
    )
    op.create_index("repomirrorconfig_mirror_type",
                    "repomirrorconfig", ["mirror_type"],
                    unique=False)
    op.create_index("repomirrorconfig_repository_id",
                    "repomirrorconfig", ["repository_id"],
                    unique=True)
    op.create_index("repomirrorconfig_root_rule_id",
                    "repomirrorconfig", ["root_rule_id"],
                    unique=False)
    op.create_index("repomirrorconfig_sync_status",
                    "repomirrorconfig", ["sync_status"],
                    unique=False)
    op.create_index(
        "repomirrorconfig_sync_transaction_id",
        "repomirrorconfig",
        ["sync_transaction_id"],
        unique=False,
    )
    op.create_index(
        "repomirrorconfig_internal_robot_id",
        "repomirrorconfig",
        ["internal_robot_id"],
        unique=False,
    )

    op.add_column(
        u"repository",
        sa.Column("state", sa.Integer(), nullable=False, server_default="0"))
    op.create_index("repository_state", "repository", ["state"], unique=False)

    op.bulk_insert(
        tables.logentrykind,
        [
            {
                "name": "repo_mirror_enabled"
            },
            {
                "name": "repo_mirror_disabled"
            },
            {
                "name": "repo_mirror_config_changed"
            },
            {
                "name": "repo_mirror_sync_started"
            },
            {
                "name": "repo_mirror_sync_failed"
            },
            {
                "name": "repo_mirror_sync_success"
            },
            {
                "name": "repo_mirror_sync_now_requested"
            },
            {
                "name": "repo_mirror_sync_tag_success"
            },
            {
                "name": "repo_mirror_sync_tag_failed"
            },
            {
                "name": "repo_mirror_sync_test_success"
            },
            {
                "name": "repo_mirror_sync_test_failed"
            },
            {
                "name": "repo_mirror_sync_test_started"
            },
            {
                "name": "change_repo_state"
            },
        ],
    )

    tester.populate_table(
        "repomirrorrule",
        [
            ("uuid", tester.TestDataType.String),
            ("repository_id", tester.TestDataType.Foreign("repository")),
            ("creation_date", tester.TestDataType.DateTime),
            ("rule_type", tester.TestDataType.Integer),
            ("rule_value", tester.TestDataType.String),
        ],
    )

    tester.populate_table(
        "repomirrorconfig",
        [
            ("repository_id", tester.TestDataType.Foreign("repository")),
            ("creation_date", tester.TestDataType.DateTime),
            ("is_enabled", tester.TestDataType.Boolean),
            ("mirror_type", tester.TestDataType.Constant(1)),
            ("internal_robot_id", tester.TestDataType.Foreign("user")),
            ("external_registry", tester.TestDataType.String),
            ("external_namespace", tester.TestDataType.String),
            ("external_repository", tester.TestDataType.String),
            ("external_registry_username", tester.TestDataType.String),
            ("external_registry_password", tester.TestDataType.String),
            ("external_registry_config", tester.TestDataType.JSON),
            ("sync_start_date", tester.TestDataType.DateTime),
            ("sync_expiration_date", tester.TestDataType.DateTime),
            ("sync_retries_remaining", tester.TestDataType.Integer),
            ("sync_status", tester.TestDataType.Constant(0)),
            ("sync_transaction_id", tester.TestDataType.String),
            ("root_rule_id", tester.TestDataType.Foreign("repomirrorrule")),
        ],
    )
Esempio n. 29
0
def downgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "tagkind",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_tagkind")),
    )
    op.create_index("tagkind_name", "tagkind", ["name"], unique=True)

    op.create_table(
        "blobplacementlocation",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_blobplacementlocation")),
    )
    op.create_index("blobplacementlocation_name",
                    "blobplacementlocation", ["name"],
                    unique=True)

    op.create_table(
        "blob",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("digest", sa.String(length=255), nullable=False),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.Column("size", sa.BigInteger(), nullable=False),
        sa.Column("uncompressed_size", sa.BigInteger(), nullable=True),
        sa.ForeignKeyConstraint(["media_type_id"], ["mediatype.id"],
                                name=op.f("fk_blob_media_type_id_mediatype")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_blob")),
    )
    op.create_index("blob_digest", "blob", ["digest"], unique=True)
    op.create_index("blob_media_type_id",
                    "blob", ["media_type_id"],
                    unique=False)

    op.create_table(
        "manifest",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("digest", sa.String(length=255), nullable=False),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.Column("manifest_json", UTF8LongText, nullable=False),
        sa.ForeignKeyConstraint(
            ["media_type_id"], ["mediatype.id"],
            name=op.f("fk_manifest_media_type_id_mediatype")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifest")),
    )
    op.create_index("manifest_digest", "manifest", ["digest"], unique=True)
    op.create_index("manifest_media_type_id",
                    "manifest", ["media_type_id"],
                    unique=False)

    op.create_table(
        "manifestlist",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("digest", sa.String(length=255), nullable=False),
        sa.Column("manifest_list_json", UTF8LongText, nullable=False),
        sa.Column("schema_version", UTF8CharField(length=255), nullable=False),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["media_type_id"],
            ["mediatype.id"],
            name=op.f("fk_manifestlist_media_type_id_mediatype"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlist")),
    )
    op.create_index("manifestlist_digest",
                    "manifestlist", ["digest"],
                    unique=True)
    op.create_index("manifestlist_media_type_id",
                    "manifestlist", ["media_type_id"],
                    unique=False)

    op.create_table(
        "blobplacement",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("blob_id", sa.Integer(), nullable=False),
        sa.Column("location_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["blob_id"], ["blob.id"],
                                name=op.f("fk_blobplacement_blob_id_blob")),
        sa.ForeignKeyConstraint(
            ["location_id"],
            ["blobplacementlocation.id"],
            name=op.f("fk_blobplacement_location_id_blobplacementlocation"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_blobplacement")),
    )
    op.create_index("blobplacement_blob_id",
                    "blobplacement", ["blob_id"],
                    unique=False)
    op.create_index(
        "blobplacement_blob_id_location_id",
        "blobplacement",
        ["blob_id", "location_id"],
        unique=True,
    )
    op.create_index("blobplacement_location_id",
                    "blobplacement", ["location_id"],
                    unique=False)

    op.create_table(
        "manifestblob",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("blob_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["blob_id"], ["blob.id"],
                                name=op.f("fk_manifestblob_blob_id_blob")),
        sa.ForeignKeyConstraint(
            ["manifest_id"], ["manifest.id"],
            name=op.f("fk_manifestblob_manifest_id_manifest")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestblob")),
    )
    op.create_index("manifestblob_blob_id",
                    "manifestblob", ["blob_id"],
                    unique=False)
    op.create_index("manifestblob_manifest_id",
                    "manifestblob", ["manifest_id"],
                    unique=False)
    op.create_index("manifestblob_manifest_id_blob_id",
                    "manifestblob", ["manifest_id", "blob_id"],
                    unique=True)

    op.create_table(
        "manifestlistmanifest",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("manifest_list_id", sa.Integer(), nullable=False),
        sa.Column("manifest_id", sa.Integer(), nullable=False),
        sa.Column("operating_system", UTF8CharField(length=255),
                  nullable=True),
        sa.Column("architecture", UTF8CharField(length=255), nullable=True),
        sa.Column("platform_json", UTF8LongText, nullable=True),
        sa.Column("media_type_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["manifest_id"],
            ["manifest.id"],
            name=op.f("fk_manifestlistmanifest_manifest_id_manifest"),
        ),
        sa.ForeignKeyConstraint(
            ["manifest_list_id"],
            ["manifestlist.id"],
            name=op.f("fk_manifestlistmanifest_manifest_list_id_manifestlist"),
        ),
        sa.ForeignKeyConstraint(
            ["media_type_id"],
            ["mediatype.id"],
            name=op.f("fk_manifestlistmanifest_media_type_id_mediatype"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_manifestlistmanifest")),
    )
    op.create_index("manifestlistmanifest_manifest_id",
                    "manifestlistmanifest", ["manifest_id"],
                    unique=False)
    op.create_index(
        "manifestlistmanifest_manifest_list_id",
        "manifestlistmanifest",
        ["manifest_list_id"],
        unique=False,
    )
    op.create_index(
        "manifestlistmanifest_manifest_listid_os_arch_mtid",
        "manifestlistmanifest",
        [
            "manifest_list_id", "operating_system", "architecture",
            "media_type_id"
        ],
        unique=False,
    )
    op.create_index(
        "manifestlistmanifest_manifest_listid_mtid",
        "manifestlistmanifest",
        ["manifest_list_id", "media_type_id"],
        unique=False,
    )
    op.create_index(
        "manifestlistmanifest_media_type_id",
        "manifestlistmanifest",
        ["media_type_id"],
        unique=False,
    )

    op.create_table(
        "tag",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", UTF8CharField(length=190), nullable=False),
        sa.Column("repository_id", sa.Integer(), nullable=False),
        sa.Column("manifest_list_id", sa.Integer(), nullable=True),
        sa.Column("lifetime_start", sa.BigInteger(), nullable=False),
        sa.Column("lifetime_end", sa.BigInteger(), nullable=True),
        sa.Column("hidden", sa.Boolean(), nullable=False),
        sa.Column("reverted", sa.Boolean(), nullable=False),
        sa.Column("protected", sa.Boolean(), nullable=False),
        sa.Column("tag_kind_id", sa.Integer(), nullable=False),
        sa.Column("linked_tag_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["linked_tag_id"], ["tag.id"],
                                name=op.f("fk_tag_linked_tag_id_tag")),
        sa.ForeignKeyConstraint(
            ["manifest_list_id"],
            ["manifestlist.id"],
            name=op.f("fk_tag_manifest_list_id_manifestlist"),
        ),
        sa.ForeignKeyConstraint(["repository_id"], ["repository.id"],
                                name=op.f("fk_tag_repository_id_repository")),
        sa.ForeignKeyConstraint(["tag_kind_id"], ["tagkind.id"],
                                name=op.f("fk_tag_tag_kind_id_tagkind")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_tag")),
    )
    op.create_index("tag_lifetime_end", "tag", ["lifetime_end"], unique=False)
    op.create_index("tag_linked_tag_id",
                    "tag", ["linked_tag_id"],
                    unique=False)
    op.create_index("tag_manifest_list_id",
                    "tag", ["manifest_list_id"],
                    unique=False)
    op.create_index("tag_repository_id",
                    "tag", ["repository_id"],
                    unique=False)
    op.create_index("tag_repository_id_name_hidden",
                    "tag", ["repository_id", "name", "hidden"],
                    unique=False)
    op.create_index(
        "tag_repository_id_name_lifetime_end",
        "tag",
        ["repository_id", "name", "lifetime_end"],
        unique=True,
    )
    op.create_index("tag_repository_id_name",
                    "tag", ["repository_id", "name"],
                    unique=False)
    op.create_index("tag_tag_kind_id", "tag", ["tag_kind_id"], unique=False)

    # ### end Alembic commands ###

    blobplacementlocation_table = table(
        "blobplacementlocation",
        column("id", sa.Integer()),
        column("name", sa.String()),
    )

    op.bulk_insert(
        blobplacementlocation_table,
        [
            {
                "name": "local_eu"
            },
            {
                "name": "local_us"
            },
        ],
    )

    tagkind_table = table(
        "tagkind",
        column("id", sa.Integer()),
        column("name", sa.String()),
    )

    op.bulk_insert(
        tagkind_table,
        [
            {
                "id": 1,
                "name": "tag"
            },
            {
                "id": 2,
                "name": "release"
            },
            {
                "id": 3,
                "name": "channel"
            },
        ],
    )
Esempio n. 30
0
def upgrade(tables, tester, progress_reporter):
    op = ProgressWrapper(original_op, progress_reporter)
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'manifest', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('repository_id', sa.Integer(), nullable=False),
        sa.Column('digest', sa.String(length=255), nullable=False),
        sa.Column('media_type_id', sa.Integer(), nullable=False),
        sa.Column('manifest_bytes', sa.Text(), nullable=False),
        sa.ForeignKeyConstraint(
            ['media_type_id'], ['mediatype.id'],
            name=op.f('fk_manifest_media_type_id_mediatype')),
        sa.ForeignKeyConstraint(
            ['repository_id'], ['repository.id'],
            name=op.f('fk_manifest_repository_id_repository')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_manifest')))
    op.create_index('manifest_digest', 'manifest', ['digest'], unique=False)
    op.create_index('manifest_media_type_id',
                    'manifest', ['media_type_id'],
                    unique=False)
    op.create_index('manifest_repository_id',
                    'manifest', ['repository_id'],
                    unique=False)
    op.create_index('manifest_repository_id_digest',
                    'manifest', ['repository_id', 'digest'],
                    unique=True)
    op.create_index('manifest_repository_id_media_type_id',
                    'manifest', ['repository_id', 'media_type_id'],
                    unique=False)
    op.create_table(
        'manifestblob', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('repository_id', sa.Integer(), nullable=False),
        sa.Column('manifest_id', sa.Integer(), nullable=False),
        sa.Column('blob_id', sa.Integer(), nullable=False),
        sa.Column('blob_index', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['blob_id'], ['imagestorage.id'],
            name=op.f('fk_manifestblob_blob_id_imagestorage')),
        sa.ForeignKeyConstraint(
            ['manifest_id'], ['manifest.id'],
            name=op.f('fk_manifestblob_manifest_id_manifest')),
        sa.ForeignKeyConstraint(
            ['repository_id'], ['repository.id'],
            name=op.f('fk_manifestblob_repository_id_repository')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestblob')))
    op.create_index('manifestblob_blob_id',
                    'manifestblob', ['blob_id'],
                    unique=False)
    op.create_index('manifestblob_manifest_id',
                    'manifestblob', ['manifest_id'],
                    unique=False)
    op.create_index('manifestblob_manifest_id_blob_id',
                    'manifestblob', ['manifest_id', 'blob_id'],
                    unique=True)
    op.create_index('manifestblob_manifest_id_blob_index',
                    'manifestblob', ['manifest_id', 'blob_index'],
                    unique=True)
    op.create_index('manifestblob_repository_id',
                    'manifestblob', ['repository_id'],
                    unique=False)
    op.create_table(
        'manifestlabel', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('repository_id', sa.Integer(), nullable=False),
        sa.Column('manifest_id', sa.Integer(), nullable=False),
        sa.Column('label_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['label_id'], ['label.id'],
                                name=op.f('fk_manifestlabel_label_id_label')),
        sa.ForeignKeyConstraint(
            ['manifest_id'], ['manifest.id'],
            name=op.f('fk_manifestlabel_manifest_id_manifest')),
        sa.ForeignKeyConstraint(
            ['repository_id'], ['repository.id'],
            name=op.f('fk_manifestlabel_repository_id_repository')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlabel')))
    op.create_index('manifestlabel_label_id',
                    'manifestlabel', ['label_id'],
                    unique=False)
    op.create_index('manifestlabel_manifest_id',
                    'manifestlabel', ['manifest_id'],
                    unique=False)
    op.create_index('manifestlabel_manifest_id_label_id',
                    'manifestlabel', ['manifest_id', 'label_id'],
                    unique=True)
    op.create_index('manifestlabel_repository_id',
                    'manifestlabel', ['repository_id'],
                    unique=False)
    op.create_table(
        'manifestlegacyimage', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('repository_id', sa.Integer(), nullable=False),
        sa.Column('manifest_id', sa.Integer(), nullable=False),
        sa.Column('image_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['image_id'], ['image.id'],
            name=op.f('fk_manifestlegacyimage_image_id_image')),
        sa.ForeignKeyConstraint(
            ['manifest_id'], ['manifest.id'],
            name=op.f('fk_manifestlegacyimage_manifest_id_manifest')),
        sa.ForeignKeyConstraint(
            ['repository_id'], ['repository.id'],
            name=op.f('fk_manifestlegacyimage_repository_id_repository')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_manifestlegacyimage')))
    op.create_index('manifestlegacyimage_image_id',
                    'manifestlegacyimage', ['image_id'],
                    unique=False)
    op.create_index('manifestlegacyimage_manifest_id',
                    'manifestlegacyimage', ['manifest_id'],
                    unique=True)
    op.create_index('manifestlegacyimage_repository_id',
                    'manifestlegacyimage', ['repository_id'],
                    unique=False)
    op.create_table(
        'tagmanifesttomanifest', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('tag_manifest_id', sa.Integer(), nullable=False),
        sa.Column('manifest_id', sa.Integer(), nullable=False),
        sa.Column('broken',
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.expression.false()),
        sa.ForeignKeyConstraint(
            ['manifest_id'], ['manifest.id'],
            name=op.f('fk_tagmanifesttomanifest_manifest_id_manifest')),
        sa.ForeignKeyConstraint(
            ['tag_manifest_id'], ['tagmanifest.id'],
            name=op.f('fk_tagmanifesttomanifest_tag_manifest_id_tagmanifest')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tagmanifesttomanifest')))
    op.create_index('tagmanifesttomanifest_broken',
                    'tagmanifesttomanifest', ['broken'],
                    unique=False)
    op.create_index('tagmanifesttomanifest_manifest_id',
                    'tagmanifesttomanifest', ['manifest_id'],
                    unique=True)
    op.create_index('tagmanifesttomanifest_tag_manifest_id',
                    'tagmanifesttomanifest', ['tag_manifest_id'],
                    unique=True)
    op.create_table(
        'tagmanifestlabelmap', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('tag_manifest_id', sa.Integer(), nullable=False),
        sa.Column('manifest_id', sa.Integer(), nullable=True),
        sa.Column('label_id', sa.Integer(), nullable=False),
        sa.Column('tag_manifest_label_id', sa.Integer(), nullable=False),
        sa.Column('manifest_label_id', sa.Integer(), nullable=True),
        sa.Column('broken_manifest',
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.expression.false()),
        sa.ForeignKeyConstraint(
            ['label_id'], ['label.id'],
            name=op.f('fk_tagmanifestlabelmap_label_id_label')),
        sa.ForeignKeyConstraint(
            ['manifest_id'], ['manifest.id'],
            name=op.f('fk_tagmanifestlabelmap_manifest_id_manifest')),
        sa.ForeignKeyConstraint(
            ['manifest_label_id'], ['manifestlabel.id'],
            name=op.f(
                'fk_tagmanifestlabelmap_manifest_label_id_manifestlabel')),
        sa.ForeignKeyConstraint(
            ['tag_manifest_id'], ['tagmanifest.id'],
            name=op.f('fk_tagmanifestlabelmap_tag_manifest_id_tagmanifest')),
        sa.ForeignKeyConstraint(
            ['tag_manifest_label_id'], ['tagmanifestlabel.id'],
            name=op.f(
                'fk_tagmanifestlabelmap_tag_manifest_label_id_tagmanifestlabel'
            )),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tagmanifestlabelmap')))
    op.create_index('tagmanifestlabelmap_broken_manifest',
                    'tagmanifestlabelmap', ['broken_manifest'],
                    unique=False)
    op.create_index('tagmanifestlabelmap_label_id',
                    'tagmanifestlabelmap', ['label_id'],
                    unique=False)
    op.create_index('tagmanifestlabelmap_manifest_id',
                    'tagmanifestlabelmap', ['manifest_id'],
                    unique=False)
    op.create_index('tagmanifestlabelmap_manifest_label_id',
                    'tagmanifestlabelmap', ['manifest_label_id'],
                    unique=False)
    op.create_index('tagmanifestlabelmap_tag_manifest_id',
                    'tagmanifestlabelmap', ['tag_manifest_id'],
                    unique=False)
    op.create_index('tagmanifestlabelmap_tag_manifest_label_id',
                    'tagmanifestlabelmap', ['tag_manifest_label_id'],
                    unique=False)
    # ### end Alembic commands ###

    for media_type in DOCKER_SCHEMA1_CONTENT_TYPES:
        op.bulk_insert(tables.mediatype, [
            {
                'name': media_type
            },
        ])

    # ### population of test data ### #
    tester.populate_table('manifest', [
        ('digest', tester.TestDataType.String),
        ('manifest_bytes', tester.TestDataType.JSON),
        ('media_type_id', tester.TestDataType.Foreign('mediatype')),
        ('repository_id', tester.TestDataType.Foreign('repository')),
    ])

    tester.populate_table('manifestblob', [
        ('manifest_id', tester.TestDataType.Foreign('manifest')),
        ('repository_id', tester.TestDataType.Foreign('repository')),
        ('blob_id', tester.TestDataType.Foreign('imagestorage')),
        ('blob_index', tester.TestDataType.Integer),
    ])

    tester.populate_table('manifestlabel', [
        ('manifest_id', tester.TestDataType.Foreign('manifest')),
        ('label_id', tester.TestDataType.Foreign('label')),
        ('repository_id', tester.TestDataType.Foreign('repository')),
    ])

    tester.populate_table('manifestlegacyimage', [
        ('manifest_id', tester.TestDataType.Foreign('manifest')),
        ('image_id', tester.TestDataType.Foreign('image')),
        ('repository_id', tester.TestDataType.Foreign('repository')),
    ])

    tester.populate_table('tagmanifesttomanifest', [
        ('manifest_id', tester.TestDataType.Foreign('manifest')),
        ('tag_manifest_id', tester.TestDataType.Foreign('tagmanifest')),
    ])

    tester.populate_table('tagmanifestlabelmap', [
        ('manifest_id', tester.TestDataType.Foreign('manifest')),
        ('tag_manifest_id', tester.TestDataType.Foreign('tagmanifest')),
        ('tag_manifest_label_id',
         tester.TestDataType.Foreign('tagmanifestlabel')),
        ('manifest_label_id', tester.TestDataType.Foreign('manifestlabel')),
        ('label_id', tester.TestDataType.Foreign('label')),
    ])