diff --git a/data/migrations/versions/5d463ea1e8a8_backfill_new_appr_tables.py b/data/migrations/versions/5d463ea1e8a8_backfill_new_appr_tables.py new file mode 100644 index 000000000..f045b2057 --- /dev/null +++ b/data/migrations/versions/5d463ea1e8a8_backfill_new_appr_tables.py @@ -0,0 +1,29 @@ +"""Backfill new appr tables + +Revision ID: 5d463ea1e8a8 +Revises: 610320e9dacf +Create Date: 2018-07-08 10:01:19.756126 + +""" + +# revision identifiers, used by Alembic. +revision = '5d463ea1e8a8' +down_revision = '610320e9dacf' + +from alembic import op +import sqlalchemy as sa +from util.migrate.table_ops import copy_table_contents + +def upgrade(tables, tester): + 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 downgrade(tables, tester): + pass diff --git a/endpoints/appr/models_cnr.py b/endpoints/appr/models_cnr.py index 046e89245..3c8ccdc6f 100644 --- a/endpoints/appr/models_cnr.py +++ b/endpoints/appr/models_cnr.py @@ -310,5 +310,5 @@ class CNRAppModel(AppRegistryDataInterface): return appr_model.blob.get_blob_locations(digest, self.models_ref) -# Phase 1: Read from old tables, disallow writing. -model = CNRAppModel(OLD_MODELS, features.READONLY_APP_REGISTRY) +# Phase 2: Read and write from new tables. +model = CNRAppModel(NEW_MODELS, features.READONLY_APP_REGISTRY) diff --git a/test/test_api_usage.py b/test/test_api_usage.py index 88d234057..c9ae64177 100644 --- a/test/test_api_usage.py +++ b/test/test_api_usage.py @@ -27,7 +27,7 @@ from app import app, config_provider, all_queues, dockerfile_build_queue, notifi from buildtrigger.basehandler import BuildTriggerHandler from initdb import setup_database_for_testing, finished_database_for_testing from data import database, model, appr_model -from data.appr_model.models import OLD_MODELS +from data.appr_model.models import NEW_MODELS from data.database import RepositoryActionCount, Repository as RepositoryTable from test.helpers import assert_action_logged from util.secscan.fake import fake_security_scanner @@ -2155,10 +2155,10 @@ class TestDeleteRepository(ApiTestCase): repository = model.repository.get_repository(ADMIN_ACCESS_USER, 'complex') # Add some CNR tags and linked tags. - base_tag = appr_model.tag.create_or_update_tag(repository, 'somebasetag', OLD_MODELS) - base_tag2 = appr_model.tag.create_or_update_tag(repository, 'somebasetag2', OLD_MODELS) - appr_model.tag.create_or_update_tag(repository, 'somelinkedtag', OLD_MODELS, linked_tag=base_tag) - appr_model.tag.create_or_update_tag(repository, 'somelinkedtag2', OLD_MODELS, linked_tag=base_tag2) + base_tag = appr_model.tag.create_or_update_tag(repository, 'somebasetag', NEW_MODELS) + base_tag2 = appr_model.tag.create_or_update_tag(repository, 'somebasetag2', NEW_MODELS) + appr_model.tag.create_or_update_tag(repository, 'somelinkedtag', NEW_MODELS, linked_tag=base_tag) + appr_model.tag.create_or_update_tag(repository, 'somelinkedtag2', NEW_MODELS, linked_tag=base_tag2) # Create some access tokens. access_token = model.token.create_access_token(repository, 'read') diff --git a/util/config/database.py b/util/config/database.py index 356e12ce3..cbd6ea78b 100644 --- a/util/config/database.py +++ b/util/config/database.py @@ -1,6 +1,6 @@ from data import model from data.appr_model import blob -from data.appr_model.models import OLD_MODELS +from data.appr_model.models import NEW_MODELS def sync_database_with_config(config): @@ -9,4 +9,4 @@ def sync_database_with_config(config): location_names = config.get('DISTRIBUTED_STORAGE_CONFIG', {}).keys() if location_names: model.image.ensure_image_locations(*location_names) - blob.ensure_blob_locations(OLD_MODELS, *location_names) + blob.ensure_blob_locations(NEW_MODELS, *location_names)