This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/migrations/versions/10b999e8db1f_fix_sequences_in_postgres.py
2015-11-30 17:59:04 -05:00

53 lines
1.1 KiB
Python

"""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 = '1849ca8199fc'
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