diff --git a/data/database.py b/data/database.py index 51eeabf6f..e687a67f2 100644 --- a/data/database.py +++ b/data/database.py @@ -253,7 +253,7 @@ class Repository(BaseModel): # Therefore, we define our own deletion order here and use the dependency system to verify it. ordered_dependencies = [RepositoryAuthorizedEmail, RepositoryTag, Image, LogEntry, RepositoryBuild, RepositoryBuildTrigger, RepositoryNotification, - RepositoryPermission, AccessToken] + RepositoryPermission, AccessToken, Star] for query, fk in self.dependencies(search_nullable=True): model = fk.model_class diff --git a/data/migrations/versions/2088f2b81010_add_stars.py b/data/migrations/versions/2088f2b81010_add_stars.py new file mode 100644 index 000000000..d8c75966c --- /dev/null +++ b/data/migrations/versions/2088f2b81010_add_stars.py @@ -0,0 +1,40 @@ +"""add stars + +Revision ID: 2088f2b81010 +Revises: 1c5b738283a5 +Create Date: 2014-12-02 17:45:00.707498 + +""" + +# revision identifiers, used by Alembic. +revision = '2088f2b81010' +down_revision = '1c5b738283a5' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +def upgrade(tables): + op.create_table('star', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('repository_id', sa.Integer(), nullable=False), + sa.Column('created', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], name=op.f('fk_star_repository_id_repository')), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_star_user_id_user')), + sa.PrimaryKeyConstraint('id', name=op.f('pk_star')) + ) + with op.batch_alter_table('star', schema=None) as batch_op: + batch_op.create_index('star_repository_id', ['repository_id'], unique=False) + batch_op.create_index('star_user_id', ['user_id'], unique=False) + batch_op.create_index('star_user_id_repository_id', ['user_id', 'repository_id'], unique=True) + +def downgrade(tables): + op.drop_constraint('fk_star_repository_id_repository', 'star', type_='foreignkey') + op.drop_constraint('fk_star_user_id_user', 'star', type_='foreignkey') + with op.batch_alter_table('star', schema=None) as batch_op: + batch_op.drop_index('star_user_id_repository_id') + batch_op.drop_index('star_user_id') + batch_op.drop_index('star_repository_id') + + op.drop_table('star') diff --git a/data/migrations/versions/3b668be15dc0_add_stars.py b/data/migrations/versions/3b668be15dc0_add_stars.py deleted file mode 100644 index 47f1f1a3a..000000000 --- a/data/migrations/versions/3b668be15dc0_add_stars.py +++ /dev/null @@ -1,38 +0,0 @@ -"""add stars - -Revision ID: 3b668be15dc0 -Revises: 204abf14783d -Create Date: 2014-11-14 14:11:18.687340 - -""" - -# revision identifiers, used by Alembic. -revision = '3b668be15dc0' -down_revision = '204abf14783d' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import mysql - -def upgrade(tables): - op.create_table('star', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('repository_id', sa.Integer(), nullable=False), - sa.Column('created', sa.DateTime(), nullable=False), - sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], name=op.f('fk_star_repository_id_repository')), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_star_user_id_user')), - sa.PrimaryKeyConstraint('id', name=op.f('pk_star')) - ) - op.create_index('star_repository_id', 'star', ['repository_id'], unique=False) - op.create_index('star_user_id', 'star', ['user_id'], unique=False) - op.create_index('star_user_id_repository_id', 'star', ['user_id', 'repository_id'], unique=True) - - -def downgrade(tables): - op.drop_constraint('fk_star_repository_id_repository', 'star', type_='foreignkey') - op.drop_constraint('fk_star_user_id_user', 'star', type_='foreignkey') - op.drop_index('star_user_id_repository_id', table_name='star') - op.drop_index('star_user_id', table_name='star') - op.drop_index('star_repository_id', table_name='star') - op.drop_table('star') diff --git a/test/data/test.db b/test/data/test.db index cdaa66e57..68f54f0a1 100644 Binary files a/test/data/test.db and b/test/data/test.db differ