Merge pull request #888 from coreos-inc/remove-hardcoded-ids
Fix seq generators for enum tables in postgres
This commit is contained in:
commit
3833fb6530
22 changed files with 157 additions and 104 deletions
|
@ -0,0 +1,53 @@
|
|||
"""Fix sequences in postgres
|
||||
|
||||
Revision ID: 10b999e8db1f
|
||||
Revises: 22af01f81722
|
||||
Create Date: 2015-11-16 14:00:05.383227
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '10b999e8db1f'
|
||||
down_revision = '22af01f81722'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
import uuid
|
||||
from peewee import CharField, IntegrityError
|
||||
|
||||
|
||||
def upgrade(tables):
|
||||
from data.database import BaseModel
|
||||
|
||||
class_names = [
|
||||
'TeamRole',
|
||||
'LoginService',
|
||||
'Visibility',
|
||||
'Role',
|
||||
'AccessTokenKind',
|
||||
'BuildTriggerService',
|
||||
'ImageStorageTransformation',
|
||||
'ImageStorageSignatureKind',
|
||||
'ImageStorageLocation',
|
||||
'LogEntryKind',
|
||||
'NotificationKind',
|
||||
'ExternalNotificationEvent',
|
||||
'ExternalNotificationMethod',
|
||||
]
|
||||
|
||||
unique_name = '%s' % uuid.uuid4()
|
||||
|
||||
for class_name in class_names:
|
||||
Model = type(class_name, (BaseModel,), {'name': CharField(index=True)})
|
||||
|
||||
for _ in xrange(50):
|
||||
try:
|
||||
Model.create(name=unique_name).delete_instance()
|
||||
break
|
||||
except IntegrityError:
|
||||
pass
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
pass
|
|
@ -20,7 +20,7 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.loginservice,
|
||||
[
|
||||
{'id':4, 'name':'google'},
|
||||
{'name':'google'},
|
||||
])
|
||||
|
||||
def downgrade(tables):
|
||||
|
|
|
@ -17,7 +17,7 @@ import sqlalchemy as sa
|
|||
def upgrade(tables):
|
||||
op.bulk_insert(tables.logentrykind,
|
||||
[
|
||||
{'id': 47, 'name':'revert_tag'},
|
||||
{'name':'revert_tag'},
|
||||
])
|
||||
|
||||
|
||||
|
@ -26,4 +26,4 @@ def downgrade(tables):
|
|||
(tables.logentrykind.delete()
|
||||
.where(tables.logentrykind.c.name == op.inline_literal('revert_tag')))
|
||||
|
||||
)
|
||||
)
|
||||
|
|
|
@ -15,7 +15,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
def upgrade(tables):
|
||||
op.bulk_insert(tables.buildtriggerservice, [{'id': 4, 'name': 'gitlab'}])
|
||||
op.bulk_insert(tables.buildtriggerservice, [{'name': 'gitlab'}])
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
|
|
|
@ -16,7 +16,7 @@ import sqlalchemy as sa
|
|||
def upgrade(tables):
|
||||
op.bulk_insert(tables.logentrykind,
|
||||
[
|
||||
{'id': 46, 'name':'repo_verb'},
|
||||
{'name':'repo_verb'},
|
||||
])
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
def upgrade(tables):
|
||||
op.bulk_insert(tables.loginservice, [{'id': 6, 'name': 'keystone'}])
|
||||
op.bulk_insert(tables.loginservice, [{'name': 'keystone'}])
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
|
|
|
@ -15,7 +15,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
def upgrade(tables):
|
||||
op.bulk_insert(tables.buildtriggerservice, [{'id': 3, 'name': 'bitbucket'}])
|
||||
op.bulk_insert(tables.buildtriggerservice, [{'name': 'bitbucket'}])
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
|
|
|
@ -23,9 +23,9 @@ def upgrade(tables):
|
|||
op.create_index('externalnotificationmethod_name', 'externalnotificationmethod', ['name'], unique=True)
|
||||
op.bulk_insert(tables.externalnotificationmethod,
|
||||
[
|
||||
{'id':1, 'name':'quay_notification'},
|
||||
{'id':2, 'name':'email'},
|
||||
{'id':3, 'name':'webhook'},
|
||||
{'name':'quay_notification'},
|
||||
{'name':'email'},
|
||||
{'name':'webhook'},
|
||||
])
|
||||
op.create_table('externalnotificationevent',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
|
@ -35,11 +35,11 @@ def upgrade(tables):
|
|||
op.create_index('externalnotificationevent_name', 'externalnotificationevent', ['name'], unique=True)
|
||||
op.bulk_insert(tables.externalnotificationevent,
|
||||
[
|
||||
{'id':1, 'name':'repo_push'},
|
||||
{'id':2, 'name':'build_queued'},
|
||||
{'id':3, 'name':'build_start'},
|
||||
{'id':4, 'name':'build_success'},
|
||||
{'id':5, 'name':'build_failure'},
|
||||
{'name':'repo_push'},
|
||||
{'name':'build_queued'},
|
||||
{'name':'build_start'},
|
||||
{'name':'build_success'},
|
||||
{'name':'build_failure'},
|
||||
])
|
||||
op.create_table('repositoryauthorizedemail',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
|
@ -74,18 +74,18 @@ def upgrade(tables):
|
|||
# Manually add the new notificationkind types
|
||||
op.bulk_insert(tables.notificationkind,
|
||||
[
|
||||
{'id':5, 'name':'repo_push'},
|
||||
{'id':6, 'name':'build_queued'},
|
||||
{'id':7, 'name':'build_start'},
|
||||
{'id':8, 'name':'build_success'},
|
||||
{'id':9, 'name':'build_failure'},
|
||||
{'name':'repo_push'},
|
||||
{'name':'build_queued'},
|
||||
{'name':'build_start'},
|
||||
{'name':'build_success'},
|
||||
{'name':'build_failure'},
|
||||
])
|
||||
|
||||
# Manually add the new logentrykind types
|
||||
op.bulk_insert(tables.logentrykind,
|
||||
[
|
||||
{'id':39, 'name':'add_repo_notification'},
|
||||
{'id':40, 'name':'delete_repo_notification'},
|
||||
{'name':'add_repo_notification'},
|
||||
{'name':'delete_repo_notification'},
|
||||
])
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
def upgrade(tables):
|
||||
op.bulk_insert(tables.buildtriggerservice, [{'id': 2, 'name': 'custom-git'}])
|
||||
op.bulk_insert(tables.buildtriggerservice, [{'name': 'custom-git'}])
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
|
|
|
@ -15,7 +15,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
def upgrade(tables):
|
||||
op.bulk_insert(tables.loginservice, [{'id': 7, 'name': 'dex'}])
|
||||
op.bulk_insert(tables.loginservice, [{'name': 'dex'}])
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
|
|
|
@ -23,7 +23,7 @@ def upgrade(tables):
|
|||
op.create_index('imagestoragetransformation_name', 'imagestoragetransformation', ['name'], unique=True)
|
||||
op.bulk_insert(tables.imagestoragetransformation,
|
||||
[
|
||||
{'id':1, 'name':'squash'},
|
||||
{'name':'squash'},
|
||||
])
|
||||
op.create_table('derivedimagestorage',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
|
|
|
@ -29,8 +29,8 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.accesstokenkind,
|
||||
[
|
||||
{'id': 1, 'name':'build-worker'},
|
||||
{'id': 2, 'name':'pushpull-token'},
|
||||
{'name':'build-worker'},
|
||||
{'name':'pushpull-token'},
|
||||
])
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import sqlalchemy as sa
|
|||
def upgrade(tables):
|
||||
op.bulk_insert(tables.loginservice,
|
||||
[
|
||||
{'id': 5, 'name':'jwtauthn'},
|
||||
{'name':'jwtauthn'},
|
||||
])
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import sqlalchemy as sa
|
|||
def upgrade(tables):
|
||||
op.bulk_insert(tables.logentrykind,
|
||||
[
|
||||
{'id': 41, 'name':'regenerate_robot_token'},
|
||||
{'name':'regenerate_robot_token'},
|
||||
])
|
||||
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ import sqlalchemy as sa
|
|||
def upgrade(tables):
|
||||
op.bulk_insert(tables.externalnotificationmethod,
|
||||
[
|
||||
{'id':4, 'name':'flowdock'},
|
||||
{'id':5, 'name':'hipchat'},
|
||||
{'id':6, 'name':'slack'},
|
||||
{'name':'flowdock'},
|
||||
{'name':'hipchat'},
|
||||
{'name':'slack'},
|
||||
])
|
||||
|
||||
def downgrade(tables):
|
||||
|
|
|
@ -16,7 +16,7 @@ import sqlalchemy as sa
|
|||
def upgrade(tables):
|
||||
op.bulk_insert(tables.notificationkind,
|
||||
[
|
||||
{'id':4, 'name':'maintenance'},
|
||||
{'name':'maintenance'},
|
||||
])
|
||||
|
||||
|
||||
|
|
|
@ -36,15 +36,15 @@ def upgrade(tables):
|
|||
# Manually add the new logentrykind types
|
||||
op.bulk_insert(tables.logentrykind,
|
||||
[
|
||||
{'id':42, 'name':'org_invite_team_member'},
|
||||
{'id':43, 'name':'org_team_member_invite_accepted'},
|
||||
{'id':44, 'name':'org_team_member_invite_declined'},
|
||||
{'id':45, 'name':'org_delete_team_member_invite'},
|
||||
{'name':'org_invite_team_member'},
|
||||
{'name':'org_team_member_invite_accepted'},
|
||||
{'name':'org_team_member_invite_declined'},
|
||||
{'name':'org_delete_team_member_invite'},
|
||||
])
|
||||
|
||||
op.bulk_insert(tables.notificationkind,
|
||||
[
|
||||
{'id':10, 'name':'org_team_invite'},
|
||||
{'name':'org_team_invite'},
|
||||
])
|
||||
|
||||
def downgrade(tables):
|
||||
|
|
|
@ -24,9 +24,9 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.loginservice,
|
||||
[
|
||||
{'id':1, 'name':'github'},
|
||||
{'id':2, 'name':'quayrobot'},
|
||||
{'id':3, 'name':'ldap'},
|
||||
{'name':'github'},
|
||||
{'name':'quayrobot'},
|
||||
{'name':'ldap'},
|
||||
])
|
||||
|
||||
op.create_table('imagestorage',
|
||||
|
@ -63,9 +63,9 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.role,
|
||||
[
|
||||
{'id':1, 'name':'admin'},
|
||||
{'id':2, 'name':'write'},
|
||||
{'id':3, 'name':'read'},
|
||||
{'name':'admin'},
|
||||
{'name':'write'},
|
||||
{'name':'read'},
|
||||
])
|
||||
|
||||
op.create_table('logentrykind',
|
||||
|
@ -77,51 +77,51 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.logentrykind,
|
||||
[
|
||||
{'id':1, 'name':'account_change_plan'},
|
||||
{'id':2, 'name':'account_change_cc'},
|
||||
{'id':3, 'name':'account_change_password'},
|
||||
{'id':4, 'name':'account_convert'},
|
||||
{'name':'account_change_plan'},
|
||||
{'name':'account_change_cc'},
|
||||
{'name':'account_change_password'},
|
||||
{'name':'account_convert'},
|
||||
|
||||
{'id':5, 'name':'create_robot'},
|
||||
{'id':6, 'name':'delete_robot'},
|
||||
{'name':'create_robot'},
|
||||
{'name':'delete_robot'},
|
||||
|
||||
{'id':7, 'name':'create_repo'},
|
||||
{'id':8, 'name':'push_repo'},
|
||||
{'id':9, 'name':'pull_repo'},
|
||||
{'id':10, 'name':'delete_repo'},
|
||||
{'id':11, 'name':'create_tag'},
|
||||
{'id':12, 'name':'move_tag'},
|
||||
{'id':13, 'name':'delete_tag'},
|
||||
{'id':14, 'name':'add_repo_permission'},
|
||||
{'id':15, 'name':'change_repo_permission'},
|
||||
{'id':16, 'name':'delete_repo_permission'},
|
||||
{'id':17, 'name':'change_repo_visibility'},
|
||||
{'id':18, 'name':'add_repo_accesstoken'},
|
||||
{'id':19, 'name':'delete_repo_accesstoken'},
|
||||
{'id':20, 'name':'add_repo_webhook'},
|
||||
{'id':21, 'name':'delete_repo_webhook'},
|
||||
{'id':22, 'name':'set_repo_description'},
|
||||
{'name':'create_repo'},
|
||||
{'name':'push_repo'},
|
||||
{'name':'pull_repo'},
|
||||
{'name':'delete_repo'},
|
||||
{'name':'create_tag'},
|
||||
{'name':'move_tag'},
|
||||
{'name':'delete_tag'},
|
||||
{'name':'add_repo_permission'},
|
||||
{'name':'change_repo_permission'},
|
||||
{'name':'delete_repo_permission'},
|
||||
{'name':'change_repo_visibility'},
|
||||
{'name':'add_repo_accesstoken'},
|
||||
{'name':'delete_repo_accesstoken'},
|
||||
{'name':'add_repo_webhook'},
|
||||
{'name':'delete_repo_webhook'},
|
||||
{'name':'set_repo_description'},
|
||||
|
||||
{'id':23, 'name':'build_dockerfile'},
|
||||
{'name':'build_dockerfile'},
|
||||
|
||||
{'id':24, 'name':'org_create_team'},
|
||||
{'id':25, 'name':'org_delete_team'},
|
||||
{'id':26, 'name':'org_add_team_member'},
|
||||
{'id':27, 'name':'org_remove_team_member'},
|
||||
{'id':28, 'name':'org_set_team_description'},
|
||||
{'id':29, 'name':'org_set_team_role'},
|
||||
{'name':'org_create_team'},
|
||||
{'name':'org_delete_team'},
|
||||
{'name':'org_add_team_member'},
|
||||
{'name':'org_remove_team_member'},
|
||||
{'name':'org_set_team_description'},
|
||||
{'name':'org_set_team_role'},
|
||||
|
||||
{'id':30, 'name':'create_prototype_permission'},
|
||||
{'id':31, 'name':'modify_prototype_permission'},
|
||||
{'id':32, 'name':'delete_prototype_permission'},
|
||||
{'name':'create_prototype_permission'},
|
||||
{'name':'modify_prototype_permission'},
|
||||
{'name':'delete_prototype_permission'},
|
||||
|
||||
{'id':33, 'name':'setup_repo_trigger'},
|
||||
{'id':34, 'name':'delete_repo_trigger'},
|
||||
{'name':'setup_repo_trigger'},
|
||||
{'name':'delete_repo_trigger'},
|
||||
|
||||
{'id':35, 'name':'create_application'},
|
||||
{'id':36, 'name':'update_application'},
|
||||
{'id':37, 'name':'delete_application'},
|
||||
{'id':38, 'name':'reset_application_client_secret'},
|
||||
{'name':'create_application'},
|
||||
{'name':'update_application'},
|
||||
{'name':'delete_application'},
|
||||
{'name':'reset_application_client_secret'},
|
||||
])
|
||||
|
||||
op.create_table('notificationkind',
|
||||
|
@ -133,9 +133,9 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.notificationkind,
|
||||
[
|
||||
{'id':1, 'name':'password_required'},
|
||||
{'id':2, 'name':'over_private_usage'},
|
||||
{'id':3, 'name':'expiring_license'},
|
||||
{'name':'password_required'},
|
||||
{'name':'over_private_usage'},
|
||||
{'name':'expiring_license'},
|
||||
])
|
||||
|
||||
op.create_table('teamrole',
|
||||
|
@ -147,9 +147,9 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.teamrole,
|
||||
[
|
||||
{'id':1, 'name':'admin'},
|
||||
{'id':2, 'name':'creator'},
|
||||
{'id':3, 'name':'member'},
|
||||
{'name':'admin'},
|
||||
{'name':'creator'},
|
||||
{'name':'member'},
|
||||
])
|
||||
|
||||
op.create_table('visibility',
|
||||
|
@ -161,8 +161,8 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.visibility,
|
||||
[
|
||||
{'id':1, 'name':'public'},
|
||||
{'id':2, 'name':'private'},
|
||||
{'name':'public'},
|
||||
{'name':'private'},
|
||||
])
|
||||
|
||||
op.create_table('user',
|
||||
|
@ -191,7 +191,7 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.buildtriggerservice,
|
||||
[
|
||||
{'id':1, 'name':'github'},
|
||||
{'name':'github'},
|
||||
])
|
||||
|
||||
op.create_table('federatedlogin',
|
||||
|
|
|
@ -38,12 +38,12 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.imagestoragetransformation,
|
||||
[
|
||||
{'id': 2, 'name':'aci'},
|
||||
{'name':'aci'},
|
||||
])
|
||||
|
||||
op.bulk_insert(tables.imagestoragesignaturekind,
|
||||
[
|
||||
{'id': 1, 'name':'gpg2'},
|
||||
{'name':'gpg2'},
|
||||
])
|
||||
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@ import sqlalchemy as sa
|
|||
def upgrade(tables):
|
||||
op.bulk_insert(tables.externalnotificationevent,
|
||||
[
|
||||
{'id':6, 'name':'vulnerability_found'},
|
||||
{'name':'vulnerability_found'},
|
||||
])
|
||||
|
||||
op.bulk_insert(tables.notificationkind,
|
||||
[
|
||||
{'id':11, 'name':'vulnerability_found'},
|
||||
{'name':'vulnerability_found'},
|
||||
])
|
||||
|
||||
|
||||
|
@ -38,4 +38,4 @@ def downgrade(tables):
|
|||
(tables.notificationkind.delete()
|
||||
.where(tables.notificationkind.c.name == op.inline_literal('vulnerability_found')))
|
||||
|
||||
)
|
||||
)
|
||||
|
|
|
@ -16,7 +16,7 @@ import sqlalchemy as sa
|
|||
def upgrade(tables):
|
||||
op.bulk_insert(tables.imagestoragelocation,
|
||||
[
|
||||
{'id':8, 'name':'s3_us_west_1'},
|
||||
{'name':'s3_us_west_1'},
|
||||
])
|
||||
|
||||
|
||||
|
|
|
@ -25,13 +25,13 @@ def upgrade(tables):
|
|||
|
||||
op.bulk_insert(tables.imagestoragelocation,
|
||||
[
|
||||
{'id':1, 'name':'s3_us_east_1'},
|
||||
{'id':2, 'name':'s3_eu_west_1'},
|
||||
{'id':3, 'name':'s3_ap_southeast_1'},
|
||||
{'id':4, 'name':'s3_ap_southeast_2'},
|
||||
{'id':5, 'name':'s3_ap_northeast_1'},
|
||||
{'id':6, 'name':'s3_sa_east_1'},
|
||||
{'id':7, 'name':'local'},
|
||||
{'name':'s3_us_east_1'},
|
||||
{'name':'s3_eu_west_1'},
|
||||
{'name':'s3_ap_southeast_1'},
|
||||
{'name':'s3_ap_southeast_2'},
|
||||
{'name':'s3_ap_northeast_1'},
|
||||
{'name':'s3_sa_east_1'},
|
||||
{'name':'local'},
|
||||
])
|
||||
|
||||
op.create_table('imagestorageplacement',
|
||||
|
|
Reference in a new issue