def upgrade(tables, tester, progress_reporter): op = ProgressWrapper(original_op, progress_reporter) # Add a 0 entry into the RepositorySearchScore table for each repository that isn't present conn = op.get_bind() conn.execute( "insert into repositorysearchscore (repository_id, score) SELECT id, 0 FROM " + "repository WHERE id not in (select repository_id from repositorysearchscore)" )
def upgrade(tables, tester, progress_reporter): op = ProgressWrapper(original_op, progress_reporter) # Backfill the queueitem table's state_id field with unique values for all entries which are # empty. conn = op.get_bind() conn.execute("update queueitem set state_id = id where state_id = ''") # ### commands auto generated by Alembic - please adjust! ### op.drop_index("queueitem_state_id", table_name="queueitem") op.create_index("queueitem_state_id", "queueitem", ["state_id"], unique=True)
def upgrade(tables, tester, progress_reporter): op = ProgressWrapper(original_op, progress_reporter) conn = op.get_bind() copy_table_contents('blob', 'apprblob', conn) copy_table_contents('manifest', 'apprmanifest', conn) copy_table_contents('manifestlist', 'apprmanifestlist', conn) copy_table_contents('blobplacement', 'apprblobplacement', conn) copy_table_contents('manifestblob', 'apprmanifestblob', conn) copy_table_contents('manifestlistmanifest', 'apprmanifestlistmanifest', conn) copy_table_contents('tag', 'apprtag', conn)
def upgrade(tables, tester, progress_reporter): op = ProgressWrapper(original_op, progress_reporter) conn = op.get_bind() copy_table_contents("blob", "apprblob", conn) copy_table_contents("manifest", "apprmanifest", conn) copy_table_contents("manifestlist", "apprmanifestlist", conn) copy_table_contents("blobplacement", "apprblobplacement", conn) copy_table_contents("manifestblob", "apprmanifestblob", conn) copy_table_contents("manifestlistmanifest", "apprmanifestlistmanifest", conn) copy_table_contents("tag", "apprtag", conn)
def run_migration(migrate_function, progress_reporter): op = ProgressWrapper(original_op, progress_reporter) conn = op.get_bind() triggers = conn.execute("SELECT id, config FROM repositorybuildtrigger") for trigger in triggers: config = json.dumps(migrate_function(json.loads(trigger[1]))) try: conn.execute( "UPDATE repositorybuildtrigger SET config=%s WHERE id=%s", config, trigger[0]) except (RevisionError, CommandError) as e: log.warning("Failed to update build trigger %s with exception: ", trigger[0], e)
def upgrade(tables, tester, progress_reporter): op = ProgressWrapper(original_op, progress_reporter) # ### commands auto generated by Alembic - please adjust! ### op.create_table( "apprblobplacementlocation", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sa.String(length=255), nullable=False), sa.PrimaryKeyConstraint("id", name=op.f("pk_apprblobplacementlocation")), ) op.create_index( "apprblobplacementlocation_name", "apprblobplacementlocation", ["name"], unique=True ) op.create_table( "apprtagkind", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sa.String(length=255), nullable=False), sa.PrimaryKeyConstraint("id", name=op.f("pk_apprtagkind")), ) op.create_index("apprtagkind_name", "apprtagkind", ["name"], unique=True) op.create_table( "apprblob", 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_apprblob_media_type_id_mediatype") ), sa.PrimaryKeyConstraint("id", name=op.f("pk_apprblob")), ) op.create_index("apprblob_digest", "apprblob", ["digest"], unique=True) op.create_index("apprblob_media_type_id", "apprblob", ["media_type_id"], unique=False) op.create_table( "apprmanifest", 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", sa.Text(), nullable=False), sa.ForeignKeyConstraint( ["media_type_id"], ["mediatype.id"], name=op.f("fk_apprmanifest_media_type_id_mediatype"), ), sa.PrimaryKeyConstraint("id", name=op.f("pk_apprmanifest")), ) op.create_index("apprmanifest_digest", "apprmanifest", ["digest"], unique=True) op.create_index("apprmanifest_media_type_id", "apprmanifest", ["media_type_id"], unique=False) op.create_table( "apprmanifestlist", sa.Column("id", sa.Integer(), nullable=False), sa.Column("digest", sa.String(length=255), nullable=False), sa.Column("manifest_list_json", sa.Text(), nullable=False), sa.Column("schema_version", sa.String(length=255), nullable=False), sa.Column("media_type_id", sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ["media_type_id"], ["mediatype.id"], name=op.f("fk_apprmanifestlist_media_type_id_mediatype"), ), sa.PrimaryKeyConstraint("id", name=op.f("pk_apprmanifestlist")), ) op.create_index("apprmanifestlist_digest", "apprmanifestlist", ["digest"], unique=True) op.create_index( "apprmanifestlist_media_type_id", "apprmanifestlist", ["media_type_id"], unique=False ) op.create_table( "apprblobplacement", 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"], ["apprblob.id"], name=op.f("fk_apprblobplacement_blob_id_apprblob") ), sa.ForeignKeyConstraint( ["location_id"], ["apprblobplacementlocation.id"], name=op.f("fk_apprblobplacement_location_id_apprblobplacementlocation"), ), sa.PrimaryKeyConstraint("id", name=op.f("pk_apprblobplacement")), ) op.create_index("apprblobplacement_blob_id", "apprblobplacement", ["blob_id"], unique=False) op.create_index( "apprblobplacement_blob_id_location_id", "apprblobplacement", ["blob_id", "location_id"], unique=True, ) op.create_index( "apprblobplacement_location_id", "apprblobplacement", ["location_id"], unique=False ) op.create_table( "apprmanifestblob", 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"], ["apprblob.id"], name=op.f("fk_apprmanifestblob_blob_id_apprblob") ), sa.ForeignKeyConstraint( ["manifest_id"], ["apprmanifest.id"], name=op.f("fk_apprmanifestblob_manifest_id_apprmanifest"), ), sa.PrimaryKeyConstraint("id", name=op.f("pk_apprmanifestblob")), ) op.create_index("apprmanifestblob_blob_id", "apprmanifestblob", ["blob_id"], unique=False) op.create_index( "apprmanifestblob_manifest_id", "apprmanifestblob", ["manifest_id"], unique=False ) op.create_index( "apprmanifestblob_manifest_id_blob_id", "apprmanifestblob", ["manifest_id", "blob_id"], unique=True, ) op.create_table( "apprmanifestlistmanifest", 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", sa.String(length=255), nullable=True), sa.Column("architecture", sa.String(length=255), nullable=True), sa.Column("platform_json", sa.Text(), nullable=True), sa.Column("media_type_id", sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ["manifest_id"], ["apprmanifest.id"], name=op.f("fk_apprmanifestlistmanifest_manifest_id_apprmanifest"), ), sa.ForeignKeyConstraint( ["manifest_list_id"], ["apprmanifestlist.id"], name=op.f("fk_apprmanifestlistmanifest_manifest_list_id_apprmanifestlist"), ), sa.ForeignKeyConstraint( ["media_type_id"], ["mediatype.id"], name=op.f("fk_apprmanifestlistmanifest_media_type_id_mediatype"), ), sa.PrimaryKeyConstraint("id", name=op.f("pk_apprmanifestlistmanifest")), ) op.create_index( "apprmanifestlistmanifest_manifest_id", "apprmanifestlistmanifest", ["manifest_id"], unique=False, ) op.create_index( "apprmanifestlistmanifest_manifest_list_id", "apprmanifestlistmanifest", ["manifest_list_id"], unique=False, ) op.create_index( "apprmanifestlistmanifest_manifest_list_id_media_type_id", "apprmanifestlistmanifest", ["manifest_list_id", "media_type_id"], unique=False, ) op.create_index( "apprmanifestlistmanifest_manifest_list_id_operating_system_arch", "apprmanifestlistmanifest", ["manifest_list_id", "operating_system", "architecture", "media_type_id"], unique=False, ) op.create_index( "apprmanifestlistmanifest_media_type_id", "apprmanifestlistmanifest", ["media_type_id"], unique=False, ) op.create_table( "apprtag", 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_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"], ["apprtag.id"], name=op.f("fk_apprtag_linked_tag_id_apprtag") ), sa.ForeignKeyConstraint( ["manifest_list_id"], ["apprmanifestlist.id"], name=op.f("fk_apprtag_manifest_list_id_apprmanifestlist"), ), sa.ForeignKeyConstraint( ["repository_id"], ["repository.id"], name=op.f("fk_apprtag_repository_id_repository") ), sa.ForeignKeyConstraint( ["tag_kind_id"], ["apprtagkind.id"], name=op.f("fk_apprtag_tag_kind_id_apprtagkind") ), sa.PrimaryKeyConstraint("id", name=op.f("pk_apprtag")), ) op.create_index("apprtag_lifetime_end", "apprtag", ["lifetime_end"], unique=False) op.create_index("apprtag_linked_tag_id", "apprtag", ["linked_tag_id"], unique=False) op.create_index("apprtag_manifest_list_id", "apprtag", ["manifest_list_id"], unique=False) op.create_index("apprtag_repository_id", "apprtag", ["repository_id"], unique=False) op.create_index( "apprtag_repository_id_name", "apprtag", ["repository_id", "name"], unique=False ) op.create_index( "apprtag_repository_id_name_hidden", "apprtag", ["repository_id", "name", "hidden"], unique=False, ) op.create_index( "apprtag_repository_id_name_lifetime_end", "apprtag", ["repository_id", "name", "lifetime_end"], unique=True, ) op.create_index("apprtag_tag_kind_id", "apprtag", ["tag_kind_id"], unique=False) # ### end Alembic commands ### conn = op.get_bind() copy_table_contents("blobplacementlocation", "apprblobplacementlocation", conn) copy_table_contents("tagkind", "apprtagkind", conn) # ### population of test data ### # tester.populate_table( "apprmanifest", [ ("digest", tester.TestDataType.String), ("media_type_id", tester.TestDataType.Foreign("mediatype")), ("manifest_json", tester.TestDataType.JSON), ], ) tester.populate_table( "apprmanifestlist", [ ("digest", tester.TestDataType.String), ("manifest_list_json", tester.TestDataType.JSON), ("schema_version", tester.TestDataType.String), ("media_type_id", tester.TestDataType.Foreign("mediatype")), ], ) tester.populate_table( "apprmanifestlistmanifest", [ ("manifest_list_id", tester.TestDataType.Foreign("apprmanifestlist")), ("manifest_id", tester.TestDataType.Foreign("apprmanifest")), ("operating_system", tester.TestDataType.String), ("architecture", tester.TestDataType.String), ("platform_json", tester.TestDataType.JSON), ("media_type_id", tester.TestDataType.Foreign("mediatype")), ], ) tester.populate_table( "apprblob", [ ("digest", tester.TestDataType.String), ("media_type_id", tester.TestDataType.Foreign("mediatype")), ("size", tester.TestDataType.BigInteger), ("uncompressed_size", tester.TestDataType.BigInteger), ], ) tester.populate_table( "apprmanifestblob", [ ("manifest_id", tester.TestDataType.Foreign("apprmanifest")), ("blob_id", tester.TestDataType.Foreign("apprblob")), ], ) tester.populate_table( "apprtag", [ ("name", tester.TestDataType.String), ("repository_id", tester.TestDataType.Foreign("repository")), ("manifest_list_id", tester.TestDataType.Foreign("apprmanifestlist")), ("lifetime_start", tester.TestDataType.Integer), ("hidden", tester.TestDataType.Boolean), ("reverted", tester.TestDataType.Boolean), ("protected", tester.TestDataType.Boolean), ("tag_kind_id", tester.TestDataType.Foreign("apprtagkind")), ], ) tester.populate_table( "apprblobplacement", [ ("blob_id", tester.TestDataType.Foreign("apprmanifestblob")), ("location_id", tester.TestDataType.Foreign("apprblobplacementlocation")), ], )
def upgrade(tables, tester, progress_reporter): op = ProgressWrapper(original_op, progress_reporter) # NOTE: Disconnects the Alembic database connection. We do this because the Peewee calls below # use a *different* connection, and if we leave the alembic connection open, it'll time out. # See: https://github.com/sqlalchemy/alembic/issues/630 op.get_bind().execute("COMMIT") op.get_bind().invalidate() from app import app if app.config.get("SETUP_COMPLETE", False) or tester.is_testing(): # AccessToken. logger.info("Backfilling encrypted credentials for access tokens") for access_token in _iterate(AccessToken, ((AccessToken.token_name >> None) | (AccessToken.token_name == ""))): logger.info( "Backfilling encrypted credentials for access token %s", access_token.id) assert access_token.code is not None assert access_token.code[:ACCESS_TOKEN_NAME_PREFIX_LENGTH] assert access_token.code[ACCESS_TOKEN_NAME_PREFIX_LENGTH:] token_name = access_token.code[:ACCESS_TOKEN_NAME_PREFIX_LENGTH] token_code = _decrypted( access_token.code[ACCESS_TOKEN_NAME_PREFIX_LENGTH:]) (AccessToken.update( token_name=token_name, token_code=token_code).where( AccessToken.id == access_token.id, AccessToken.code == access_token.code).execute()) assert AccessToken.select().where( AccessToken.token_name >> None).count() == 0 # Robots. logger.info("Backfilling encrypted credentials for robots") while True: has_row = False query = (User.select().join( RobotAccountToken, JOIN.LEFT_OUTER).where( User.robot == True, RobotAccountToken.id >> None).limit(BATCH_SIZE)) for robot_user in query: logger.info("Backfilling encrypted credentials for robot %s", robot_user.id) has_row = True try: RobotAccountToken.create( robot_account=robot_user, token=_decrypted(robot_user.email), fully_migrated=False, ) except IntegrityError: break if not has_row: break # RepositoryBuildTrigger logger.info( "Backfilling encrypted credentials for repo build triggers") for repo_build_trigger in _iterate( RepositoryBuildTrigger, (RepositoryBuildTrigger.fully_migrated == False)): logger.info( "Backfilling encrypted credentials for repo build trigger %s", repo_build_trigger.id) (RepositoryBuildTrigger.update( secure_auth_token=_decrypted(repo_build_trigger.auth_token), secure_private_key=_decrypted(repo_build_trigger.private_key), fully_migrated=True, ).where( RepositoryBuildTrigger.id == repo_build_trigger.id, RepositoryBuildTrigger.uuid == repo_build_trigger.uuid, ).execute()) assert (RepositoryBuildTrigger.select().where( RepositoryBuildTrigger.fully_migrated == False).count()) == 0 # AppSpecificAuthToken logger.info( "Backfilling encrypted credentials for app specific auth tokens") for token in _iterate( AppSpecificAuthToken, ((AppSpecificAuthToken.token_name >> None) | (AppSpecificAuthToken.token_name == "") | (AppSpecificAuthToken.token_secret >> None)), ): logger.info( "Backfilling encrypted credentials for app specific auth %s", token.id) assert token.token_code[AST_TOKEN_NAME_PREFIX_LENGTH:] token_name = token.token_code[:AST_TOKEN_NAME_PREFIX_LENGTH] token_secret = _decrypted( token.token_code[AST_TOKEN_NAME_PREFIX_LENGTH:]) assert token_name assert token_secret (AppSpecificAuthToken.update( token_name=token_name, token_secret=token_secret).where( AppSpecificAuthToken.id == token.id, AppSpecificAuthToken.token_code == token.token_code, ).execute()) assert (AppSpecificAuthToken.select().where( AppSpecificAuthToken.token_name >> None).count()) == 0 # OAuthAccessToken logger.info("Backfilling credentials for OAuth access tokens") for token in _iterate( OAuthAccessToken, ((OAuthAccessToken.token_name >> None) | (OAuthAccessToken.token_name == "")), ): logger.info("Backfilling credentials for OAuth access token %s", token.id) token_name = token.access_token[:OAUTH_ACCESS_TOKEN_PREFIX_LENGTH] token_code = Credential.from_string( token.access_token[OAUTH_ACCESS_TOKEN_PREFIX_LENGTH:]) assert token_name assert token.access_token[OAUTH_ACCESS_TOKEN_PREFIX_LENGTH:] (OAuthAccessToken.update( token_name=token_name, token_code=token_code).where( OAuthAccessToken.id == token.id, OAuthAccessToken.access_token == token.access_token, ).execute()) assert (OAuthAccessToken.select().where( OAuthAccessToken.token_name >> None).count()) == 0 # OAuthAuthorizationCode logger.info("Backfilling credentials for OAuth auth code") for code in _iterate( OAuthAuthorizationCode, ((OAuthAuthorizationCode.code_name >> None) | (OAuthAuthorizationCode.code_name == "")), ): logger.info("Backfilling credentials for OAuth auth code %s", code.id) user_code = code.code or random_string_generator( AUTHORIZATION_CODE_PREFIX_LENGTH * 2)() code_name = user_code[:AUTHORIZATION_CODE_PREFIX_LENGTH] code_credential = Credential.from_string( user_code[AUTHORIZATION_CODE_PREFIX_LENGTH:]) assert code_name assert user_code[AUTHORIZATION_CODE_PREFIX_LENGTH:] (OAuthAuthorizationCode.update( code_name=code_name, code_credential=code_credential).where( OAuthAuthorizationCode.id == code.id).execute()) assert (OAuthAuthorizationCode.select().where( OAuthAuthorizationCode.code_name >> None).count()) == 0 # OAuthApplication logger.info("Backfilling secret for OAuth applications") for app in _iterate(OAuthApplication, OAuthApplication.fully_migrated == False): logger.info("Backfilling secret for OAuth application %s", app.id) client_secret = app.client_secret or str(uuid.uuid4()) secure_client_secret = _decrypted(client_secret) (OAuthApplication.update( secure_client_secret=secure_client_secret, fully_migrated=True).where( OAuthApplication.id == app.id, OAuthApplication.fully_migrated == False).execute()) assert (OAuthApplication.select().where( OAuthApplication.fully_migrated == False).count()) == 0
def upgrade(tables, tester, progress_reporter): op = ProgressWrapper(original_op, progress_reporter) # ### commands auto generated by Alembic - please adjust! ### op.create_table('apprblobplacementlocation', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False), sa.PrimaryKeyConstraint('id', name=op.f('pk_apprblobplacementlocation')) ) op.create_index('apprblobplacementlocation_name', 'apprblobplacementlocation', ['name'], unique=True) op.create_table('apprtagkind', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False), sa.PrimaryKeyConstraint('id', name=op.f('pk_apprtagkind')) ) op.create_index('apprtagkind_name', 'apprtagkind', ['name'], unique=True) op.create_table('apprblob', 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_apprblob_media_type_id_mediatype')), sa.PrimaryKeyConstraint('id', name=op.f('pk_apprblob')) ) op.create_index('apprblob_digest', 'apprblob', ['digest'], unique=True) op.create_index('apprblob_media_type_id', 'apprblob', ['media_type_id'], unique=False) op.create_table('apprmanifest', 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', sa.Text(), nullable=False), sa.ForeignKeyConstraint(['media_type_id'], ['mediatype.id'], name=op.f('fk_apprmanifest_media_type_id_mediatype')), sa.PrimaryKeyConstraint('id', name=op.f('pk_apprmanifest')) ) op.create_index('apprmanifest_digest', 'apprmanifest', ['digest'], unique=True) op.create_index('apprmanifest_media_type_id', 'apprmanifest', ['media_type_id'], unique=False) op.create_table('apprmanifestlist', sa.Column('id', sa.Integer(), nullable=False), sa.Column('digest', sa.String(length=255), nullable=False), sa.Column('manifest_list_json', sa.Text(), nullable=False), sa.Column('schema_version', sa.String(length=255), nullable=False), sa.Column('media_type_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint(['media_type_id'], ['mediatype.id'], name=op.f('fk_apprmanifestlist_media_type_id_mediatype')), sa.PrimaryKeyConstraint('id', name=op.f('pk_apprmanifestlist')) ) op.create_index('apprmanifestlist_digest', 'apprmanifestlist', ['digest'], unique=True) op.create_index('apprmanifestlist_media_type_id', 'apprmanifestlist', ['media_type_id'], unique=False) op.create_table('apprblobplacement', 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'], ['apprblob.id'], name=op.f('fk_apprblobplacement_blob_id_apprblob')), sa.ForeignKeyConstraint(['location_id'], ['apprblobplacementlocation.id'], name=op.f('fk_apprblobplacement_location_id_apprblobplacementlocation')), sa.PrimaryKeyConstraint('id', name=op.f('pk_apprblobplacement')) ) op.create_index('apprblobplacement_blob_id', 'apprblobplacement', ['blob_id'], unique=False) op.create_index('apprblobplacement_blob_id_location_id', 'apprblobplacement', ['blob_id', 'location_id'], unique=True) op.create_index('apprblobplacement_location_id', 'apprblobplacement', ['location_id'], unique=False) op.create_table('apprmanifestblob', 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'], ['apprblob.id'], name=op.f('fk_apprmanifestblob_blob_id_apprblob')), sa.ForeignKeyConstraint(['manifest_id'], ['apprmanifest.id'], name=op.f('fk_apprmanifestblob_manifest_id_apprmanifest')), sa.PrimaryKeyConstraint('id', name=op.f('pk_apprmanifestblob')) ) op.create_index('apprmanifestblob_blob_id', 'apprmanifestblob', ['blob_id'], unique=False) op.create_index('apprmanifestblob_manifest_id', 'apprmanifestblob', ['manifest_id'], unique=False) op.create_index('apprmanifestblob_manifest_id_blob_id', 'apprmanifestblob', ['manifest_id', 'blob_id'], unique=True) op.create_table('apprmanifestlistmanifest', 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', sa.String(length=255), nullable=True), sa.Column('architecture', sa.String(length=255), nullable=True), sa.Column('platform_json', sa.Text(), nullable=True), sa.Column('media_type_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint(['manifest_id'], ['apprmanifest.id'], name=op.f('fk_apprmanifestlistmanifest_manifest_id_apprmanifest')), sa.ForeignKeyConstraint(['manifest_list_id'], ['apprmanifestlist.id'], name=op.f('fk_apprmanifestlistmanifest_manifest_list_id_apprmanifestlist')), sa.ForeignKeyConstraint(['media_type_id'], ['mediatype.id'], name=op.f('fk_apprmanifestlistmanifest_media_type_id_mediatype')), sa.PrimaryKeyConstraint('id', name=op.f('pk_apprmanifestlistmanifest')) ) op.create_index('apprmanifestlistmanifest_manifest_id', 'apprmanifestlistmanifest', ['manifest_id'], unique=False) op.create_index('apprmanifestlistmanifest_manifest_list_id', 'apprmanifestlistmanifest', ['manifest_list_id'], unique=False) op.create_index('apprmanifestlistmanifest_manifest_list_id_media_type_id', 'apprmanifestlistmanifest', ['manifest_list_id', 'media_type_id'], unique=False) op.create_index('apprmanifestlistmanifest_manifest_list_id_operating_system_arch', 'apprmanifestlistmanifest', ['manifest_list_id', 'operating_system', 'architecture', 'media_type_id'], unique=False) op.create_index('apprmanifestlistmanifest_media_type_id', 'apprmanifestlistmanifest', ['media_type_id'], unique=False) op.create_table('apprtag', 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_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'], ['apprtag.id'], name=op.f('fk_apprtag_linked_tag_id_apprtag')), sa.ForeignKeyConstraint(['manifest_list_id'], ['apprmanifestlist.id'], name=op.f('fk_apprtag_manifest_list_id_apprmanifestlist')), sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], name=op.f('fk_apprtag_repository_id_repository')), sa.ForeignKeyConstraint(['tag_kind_id'], ['apprtagkind.id'], name=op.f('fk_apprtag_tag_kind_id_apprtagkind')), sa.PrimaryKeyConstraint('id', name=op.f('pk_apprtag')) ) op.create_index('apprtag_lifetime_end', 'apprtag', ['lifetime_end'], unique=False) op.create_index('apprtag_linked_tag_id', 'apprtag', ['linked_tag_id'], unique=False) op.create_index('apprtag_manifest_list_id', 'apprtag', ['manifest_list_id'], unique=False) op.create_index('apprtag_repository_id', 'apprtag', ['repository_id'], unique=False) op.create_index('apprtag_repository_id_name', 'apprtag', ['repository_id', 'name'], unique=False) op.create_index('apprtag_repository_id_name_hidden', 'apprtag', ['repository_id', 'name', 'hidden'], unique=False) op.create_index('apprtag_repository_id_name_lifetime_end', 'apprtag', ['repository_id', 'name', 'lifetime_end'], unique=True) op.create_index('apprtag_tag_kind_id', 'apprtag', ['tag_kind_id'], unique=False) # ### end Alembic commands ### conn = op.get_bind() copy_table_contents('blobplacementlocation', 'apprblobplacementlocation', conn) copy_table_contents('tagkind', 'apprtagkind', conn) # ### population of test data ### # tester.populate_table('apprmanifest', [ ('digest', tester.TestDataType.String), ('media_type_id', tester.TestDataType.Foreign('mediatype')), ('manifest_json', tester.TestDataType.JSON), ]) tester.populate_table('apprmanifestlist', [ ('digest', tester.TestDataType.String), ('manifest_list_json', tester.TestDataType.JSON), ('schema_version', tester.TestDataType.String), ('media_type_id', tester.TestDataType.Foreign('mediatype')), ]) tester.populate_table('apprmanifestlistmanifest', [ ('manifest_list_id', tester.TestDataType.Foreign('apprmanifestlist')), ('manifest_id', tester.TestDataType.Foreign('apprmanifest')), ('operating_system', tester.TestDataType.String), ('architecture', tester.TestDataType.String), ('platform_json', tester.TestDataType.JSON), ('media_type_id', tester.TestDataType.Foreign('mediatype')), ]) tester.populate_table('apprblob', [ ('digest', tester.TestDataType.String), ('media_type_id', tester.TestDataType.Foreign('mediatype')), ('size', tester.TestDataType.BigInteger), ('uncompressed_size', tester.TestDataType.BigInteger), ]) tester.populate_table('apprmanifestblob', [ ('manifest_id', tester.TestDataType.Foreign('apprmanifest')), ('blob_id', tester.TestDataType.Foreign('apprblob')), ]) tester.populate_table('apprtag', [ ('name', tester.TestDataType.String), ('repository_id', tester.TestDataType.Foreign('repository')), ('manifest_list_id', tester.TestDataType.Foreign('apprmanifestlist')), ('lifetime_start', tester.TestDataType.Integer), ('hidden', tester.TestDataType.Boolean), ('reverted', tester.TestDataType.Boolean), ('protected', tester.TestDataType.Boolean), ('tag_kind_id', tester.TestDataType.Foreign('apprtagkind')), ]) tester.populate_table('apprblobplacement', [ ('blob_id', tester.TestDataType.Foreign('apprmanifestblob')), ('location_id', tester.TestDataType.Foreign('apprblobplacementlocation')), ])