Fix all of the upgrades and downgrades to work on both mysql and postgres.
This commit is contained in:
parent
9d898bca65
commit
c4266140e2
4 changed files with 15 additions and 16 deletions
|
@ -44,11 +44,11 @@ def downgrade(tables):
|
||||||
op.create_index('notificationkind_name', 'notificationkind', ['name'], unique=False)
|
op.create_index('notificationkind_name', 'notificationkind', ['name'], unique=False)
|
||||||
op.drop_index('logentrykind_name', table_name='logentrykind')
|
op.drop_index('logentrykind_name', table_name='logentrykind')
|
||||||
op.create_index('logentrykind_name', 'logentrykind', ['name'], unique=False)
|
op.create_index('logentrykind_name', 'logentrykind', ['name'], unique=False)
|
||||||
op.add_column('image', sa.Column('created', mysql.DATETIME(), nullable=True))
|
op.add_column('image', sa.Column('created', sa.DateTime(), nullable=True))
|
||||||
op.add_column('image', sa.Column('command', mysql.LONGTEXT(), nullable=True))
|
op.add_column('image', sa.Column('command', sa.Text(), nullable=True))
|
||||||
op.add_column('image', sa.Column('image_size', mysql.BIGINT(display_width=20), nullable=True))
|
op.add_column('image', sa.Column('image_size', sa.BigInteger(), nullable=True))
|
||||||
op.add_column('image', sa.Column('checksum', mysql.VARCHAR(length=255), nullable=True))
|
op.add_column('image', sa.Column('checksum', sa.String(length=255), nullable=True))
|
||||||
op.add_column('image', sa.Column('comment', mysql.LONGTEXT(), nullable=True))
|
op.add_column('image', sa.Column('comment', sa.Text(), nullable=True))
|
||||||
op.drop_index('buildtriggerservice_name', table_name='buildtriggerservice')
|
op.drop_index('buildtriggerservice_name', table_name='buildtriggerservice')
|
||||||
op.create_index('buildtriggerservice_name', 'buildtriggerservice', ['name'], unique=False)
|
op.create_index('buildtriggerservice_name', 'buildtriggerservice', ['name'], unique=False)
|
||||||
### end Alembic commands ###
|
### end Alembic commands ###
|
||||||
|
|
|
@ -16,8 +16,8 @@ import sqlalchemy as sa
|
||||||
|
|
||||||
def upgrade(tables):
|
def upgrade(tables):
|
||||||
conn = op.get_bind()
|
conn = op.get_bind()
|
||||||
conn.execute('update repository set namespace_user_id = (select id from user where user.username = repository.namespace) where namespace_user_id is NULL')
|
user_table_name_escaped = conn.dialect.identifier_preparer.format_table(tables['user'])
|
||||||
|
conn.execute('update repository set namespace_user_id = (select id from {0} where {0}.username = repository.namespace) where namespace_user_id is NULL'.format(user_table_name_escaped))
|
||||||
op.create_index('repository_namespace_user_id_name', 'repository', ['namespace_user_id', 'name'], unique=True)
|
op.create_index('repository_namespace_user_id_name', 'repository', ['namespace_user_id', 'name'], unique=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,8 @@ def upgrade(tables):
|
||||||
|
|
||||||
def downgrade(tables):
|
def downgrade(tables):
|
||||||
conn = op.get_bind()
|
conn = op.get_bind()
|
||||||
conn.execute('update repository set namespace = (select username from user where user.id = repository.namespace_user_id) where namespace is NULL')
|
user_table_name_escaped = conn.dialect.identifier_preparer.format_table(tables['user'])
|
||||||
|
conn.execute('update repository set namespace = (select username from {0} where {0}.id = repository.namespace_user_id) where namespace is NULL'.format(user_table_name_escaped))
|
||||||
|
|
||||||
op.create_index('repository_namespace_name', 'repository', ['namespace', 'name'], unique=True)
|
op.create_index('repository_namespace_name', 'repository', ['namespace', 'name'], unique=True)
|
||||||
op.alter_column('repository', 'namespace', nullable=False, existing_type=sa.String(length=255))
|
op.alter_column('repository', 'namespace', nullable=False, existing_type=sa.String(length=255))
|
||||||
|
|
|
@ -23,13 +23,11 @@ def upgrade(tables):
|
||||||
def downgrade(tables):
|
def downgrade(tables):
|
||||||
### commands auto generated by Alembic - please adjust! ###
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
op.create_table('webhook',
|
op.create_table('webhook',
|
||||||
sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.Column('public_id', mysql.VARCHAR(length=255), nullable=False),
|
sa.Column('public_id', sa.String(length=255), nullable=False),
|
||||||
sa.Column('repository_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False),
|
sa.Column('repository_id', sa.Integer(), nullable=False),
|
||||||
sa.Column('parameters', mysql.LONGTEXT(), nullable=False),
|
sa.Column('parameters', sa.Text(), nullable=False),
|
||||||
sa.ForeignKeyConstraint(['repository_id'], [u'repository.id'], name=u'fk_webhook_repository_repository_id'),
|
sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], ),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id')
|
||||||
mysql_default_charset=u'latin1',
|
|
||||||
mysql_engine=u'InnoDB'
|
|
||||||
)
|
)
|
||||||
### end Alembic commands ###
|
### end Alembic commands ###
|
||||||
|
|
Reference in a new issue