"""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