diff --git a/data/database.py b/data/database.py index b0b1c031a..a57b6cfb9 100644 --- a/data/database.py +++ b/data/database.py @@ -256,7 +256,7 @@ class EmailConfirmation(BaseModel): class ImageStorage(BaseModel): - uuid = CharField(default=uuid_generator, index=True) + uuid = CharField(default=uuid_generator, index=True, unique=True) checksum = CharField(null=True) created = DateTimeField(null=True) comment = TextField(null=True) diff --git a/data/migrations/migration.sh b/data/migrations/migration.sh index 98a12d6ac..73100b1a8 100755 --- a/data/migrations/migration.sh +++ b/data/migrations/migration.sh @@ -35,11 +35,11 @@ down_postgres() { } gen_migrate() { - # Generate the migration to the current model. - GENMIGRATE=$1 PYTHONPATH=. alembic revision --autogenerate -m "$@" - # Generate a SQLite database with the schema as defined by the existing alembic model. GENMIGRATE=$1 PYTHONPATH=. alembic upgrade head + + # Generate the migration to the current model. + GENMIGRATE=$1 PYTHONPATH=. alembic revision --autogenerate -m "$2" } test_migrate() { @@ -59,7 +59,7 @@ if [ ! -z "$@" ] then set +e echo '> Generating Migration' - gen_migrate "mysql" + gen_migrate "mysql" "$@" set -e fi diff --git a/data/migrations/versions/3b4d3a4461dc_add_support_for_squashed_images.py b/data/migrations/versions/3b4d3a4461dc_add_support_for_squashed_images.py index 7d85f0508..dc01f8676 100644 --- a/data/migrations/versions/3b4d3a4461dc_add_support_for_squashed_images.py +++ b/data/migrations/versions/3b4d3a4461dc_add_support_for_squashed_images.py @@ -35,23 +35,11 @@ def upgrade(tables): op.create_index('derivedimagestorage_source_id', 'derivedimagestorage', ['source_id'], unique=False) op.create_index('derivedimagestorage_source_id_transformation_id', 'derivedimagestorage', ['source_id', 'transformation_id'], unique=True) op.create_index('derivedimagestorage_transformation_id', 'derivedimagestorage', ['transformation_id'], unique=False) - op.drop_index('image_repository_id_docker_image_id', table_name='image') - op.create_index('image_repository_id_docker_image_id', 'image', ['repository_id', 'docker_image_id'], unique=True) - op.drop_index('imagestorage_uuid', table_name='imagestorage') - op.create_index('imagestorage_uuid', 'imagestorage', ['uuid'], unique=False) - op.drop_column(u'repository', 'namespace') - op.create_index('repository_namespace_user_id', 'repository', ['namespace_user_id'], unique=False) ### end Alembic commands ### def downgrade(tables): ### commands auto generated by Alembic - please adjust! ### - op.drop_index('repository_namespace_user_id', table_name='repository') - op.add_column(u'repository', sa.Column('namespace', sa.String(length=255), nullable=True)) - op.drop_index('imagestorage_uuid', table_name='imagestorage') - op.create_index('imagestorage_uuid', 'imagestorage', ['uuid'], unique=True) - op.drop_index('image_repository_id_docker_image_id', table_name='image') - op.create_index('image_repository_id_docker_image_id', 'image', ['repository_id', 'docker_image_id'], unique=False) op.drop_table('derivedimagestorage') op.drop_table('imagestoragetransformation') ### end Alembic commands ### diff --git a/data/migrations/versions/5a07499ce53f_set_up_initial_database.py b/data/migrations/versions/5a07499ce53f_set_up_initial_database.py index f67224645..78d7674bd 100644 --- a/data/migrations/versions/5a07499ce53f_set_up_initial_database.py +++ b/data/migrations/versions/5a07499ce53f_set_up_initial_database.py @@ -378,7 +378,7 @@ def upgrade(tables): ) op.create_index('image_ancestors', 'image', ['ancestors'], unique=False) op.create_index('image_repository_id', 'image', ['repository_id'], unique=False) - op.create_index('image_repository_id_docker_image_id', 'image', ['repository_id', 'docker_image_id'], unique=False) + op.create_index('image_repository_id_docker_image_id', 'image', ['repository_id', 'docker_image_id'], unique=True) op.create_index('image_storage_id', 'image', ['storage_id'], unique=False) op.create_table('permissionprototype', sa.Column('id', sa.Integer(), nullable=False),