52 lines
1.1 KiB
Python
52 lines
1.1 KiB
Python
import uuid
|
|
import logging
|
|
|
|
from peewee import IntegrityError, CharField
|
|
|
|
from app import app
|
|
from data.database import BaseModel
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
ENUM_CLASSES_WITH_SEQUENCES = [
|
|
'TeamRole',
|
|
'LoginService',
|
|
'Visibility',
|
|
'Role',
|
|
'AccessTokenKind',
|
|
'BuildTriggerService',
|
|
'ImageStorageTransformation',
|
|
'ImageStorageSignatureKind',
|
|
'ImageStorageLocation',
|
|
'LogEntryKind',
|
|
'NotificationKind',
|
|
'ExternalNotificationEvent',
|
|
'ExternalNotificationMethod',
|
|
]
|
|
|
|
|
|
def reset_enum_sequences():
|
|
for class_name in ENUM_CLASSES_WITH_SEQUENCES:
|
|
reset_sequence(class_name)
|
|
|
|
|
|
def reset_sequence(class_name):
|
|
logger.info('Resetting sequence for table: %s', class_name.lower())
|
|
unique_name = '%s' % uuid.uuid4()
|
|
|
|
Model = type(class_name, (BaseModel,), {'name': CharField(index=True)})
|
|
|
|
for skips in xrange(50):
|
|
try:
|
|
Model.create(name=unique_name).delete_instance()
|
|
logger.info('Advanced sequence %s numbers', skips)
|
|
break
|
|
except IntegrityError:
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
reset_enum_sequences()
|