From c4266140e28356d50104906ef196664dbb08aa6d Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Mon, 6 Oct 2014 16:40:44 -0400 Subject: [PATCH] Fix all of the upgrades and downgrades to work on both mysql and postgres. --- ...5b38649_remove_fields_from_image_table_that_.py | 10 +++++----- ...fe1194671_backfill_the_namespace_user_fields.py | 4 ++-- ...a1087b007d_allow_the_namespace_column_to_be_.py | 3 ++- .../f42b0ea7a4d_remove_the_old_webhooks_table.py | 14 ++++++-------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/data/migrations/versions/201d55b38649_remove_fields_from_image_table_that_.py b/data/migrations/versions/201d55b38649_remove_fields_from_image_table_that_.py index d50c3a592..8185c1118 100644 --- a/data/migrations/versions/201d55b38649_remove_fields_from_image_table_that_.py +++ b/data/migrations/versions/201d55b38649_remove_fields_from_image_table_that_.py @@ -44,11 +44,11 @@ def downgrade(tables): op.create_index('notificationkind_name', 'notificationkind', ['name'], unique=False) op.drop_index('logentrykind_name', table_name='logentrykind') 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('command', mysql.LONGTEXT(), nullable=True)) - op.add_column('image', sa.Column('image_size', mysql.BIGINT(display_width=20), nullable=True)) - op.add_column('image', sa.Column('checksum', mysql.VARCHAR(length=255), nullable=True)) - op.add_column('image', sa.Column('comment', mysql.LONGTEXT(), nullable=True)) + op.add_column('image', sa.Column('created', sa.DateTime(), nullable=True)) + op.add_column('image', sa.Column('command', sa.Text(), nullable=True)) + op.add_column('image', sa.Column('image_size', sa.BigInteger(), nullable=True)) + op.add_column('image', sa.Column('checksum', sa.String(length=255), nullable=True)) + op.add_column('image', sa.Column('comment', sa.Text(), nullable=True)) op.drop_index('buildtriggerservice_name', table_name='buildtriggerservice') op.create_index('buildtriggerservice_name', 'buildtriggerservice', ['name'], unique=False) ### end Alembic commands ### diff --git a/data/migrations/versions/3f4fe1194671_backfill_the_namespace_user_fields.py b/data/migrations/versions/3f4fe1194671_backfill_the_namespace_user_fields.py index 6f40f4fc0..4a1e2fe9d 100644 --- a/data/migrations/versions/3f4fe1194671_backfill_the_namespace_user_fields.py +++ b/data/migrations/versions/3f4fe1194671_backfill_the_namespace_user_fields.py @@ -16,8 +16,8 @@ import sqlalchemy as sa def upgrade(tables): 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) diff --git a/data/migrations/versions/9a1087b007d_allow_the_namespace_column_to_be_.py b/data/migrations/versions/9a1087b007d_allow_the_namespace_column_to_be_.py index 9b63ae190..a0726bf3b 100644 --- a/data/migrations/versions/9a1087b007d_allow_the_namespace_column_to_be_.py +++ b/data/migrations/versions/9a1087b007d_allow_the_namespace_column_to_be_.py @@ -22,7 +22,8 @@ def upgrade(tables): def downgrade(tables): 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.alter_column('repository', 'namespace', nullable=False, existing_type=sa.String(length=255)) diff --git a/data/migrations/versions/f42b0ea7a4d_remove_the_old_webhooks_table.py b/data/migrations/versions/f42b0ea7a4d_remove_the_old_webhooks_table.py index 9ceab4218..5b3f6c812 100644 --- a/data/migrations/versions/f42b0ea7a4d_remove_the_old_webhooks_table.py +++ b/data/migrations/versions/f42b0ea7a4d_remove_the_old_webhooks_table.py @@ -23,13 +23,11 @@ def upgrade(tables): def downgrade(tables): ### commands auto generated by Alembic - please adjust! ### op.create_table('webhook', - sa.Column('id', mysql.INTEGER(display_width=11), nullable=False), - sa.Column('public_id', mysql.VARCHAR(length=255), nullable=False), - sa.Column('repository_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False), - sa.Column('parameters', mysql.LONGTEXT(), nullable=False), - sa.ForeignKeyConstraint(['repository_id'], [u'repository.id'], name=u'fk_webhook_repository_repository_id'), - sa.PrimaryKeyConstraint('id'), - mysql_default_charset=u'latin1', - mysql_engine=u'InnoDB' + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('public_id', sa.String(length=255), nullable=False), + sa.Column('repository_id', sa.Integer(), nullable=False), + sa.Column('parameters', sa.Text(), nullable=False), + sa.ForeignKeyConstraint(['repository_id'], ['repository.id'], ), + sa.PrimaryKeyConstraint('id') ) ### end Alembic commands ###