From cd245e62bf567da7979f601eb3c2793a28b1267e Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Fri, 13 Feb 2015 11:56:59 -0500 Subject: [PATCH 1/2] Remove the access_token_id column from log entries. --- ...1d2d86d09fcd_actually_remove_the_column.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 data/migrations/versions/1d2d86d09fcd_actually_remove_the_column.py diff --git a/data/migrations/versions/1d2d86d09fcd_actually_remove_the_column.py b/data/migrations/versions/1d2d86d09fcd_actually_remove_the_column.py new file mode 100644 index 000000000..bfbea380e --- /dev/null +++ b/data/migrations/versions/1d2d86d09fcd_actually_remove_the_column.py @@ -0,0 +1,30 @@ +"""Actually remove the column access_token_id + +Revision ID: 1d2d86d09fcd +Revises: 14fe12ade3df +Create Date: 2015-02-12 16:27:30.260797 + +""" + +# revision identifiers, used by Alembic. +revision = '1d2d86d09fcd' +down_revision = '14fe12ade3df' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +def upgrade(tables): + ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(u'fk_logentry_access_token_id_accesstoken', 'logentry', type_='foreignkey') + op.drop_index('logentry_access_token_id', table_name='logentry') + op.drop_column('logentry', 'access_token_id') + ### end Alembic commands ### + + +def downgrade(tables): + ### commands auto generated by Alembic - please adjust! ### + op.add_column('logentry', sa.Column('access_token_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True)) + op.create_foreign_key(u'fk_logentry_access_token_id_accesstoken', 'logentry', 'accesstoken', ['access_token_id'], ['id']) + op.create_index('logentry_access_token_id', 'logentry', ['access_token_id'], unique=False) + ### end Alembic commands ### From 2743fe6f4da5b757bf8f2da765685d3a4945c289 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Fri, 13 Feb 2015 13:11:50 -0500 Subject: [PATCH 2/2] Trap migration exceptions for the migration that we expect to fail in prod. --- ...1d2d86d09fcd_actually_remove_the_column.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/data/migrations/versions/1d2d86d09fcd_actually_remove_the_column.py b/data/migrations/versions/1d2d86d09fcd_actually_remove_the_column.py index bfbea380e..a7942b7d4 100644 --- a/data/migrations/versions/1d2d86d09fcd_actually_remove_the_column.py +++ b/data/migrations/versions/1d2d86d09fcd_actually_remove_the_column.py @@ -13,18 +13,25 @@ down_revision = '14fe12ade3df' from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import mysql +from sqlalchemy.exc import InternalError def upgrade(tables): ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(u'fk_logentry_access_token_id_accesstoken', 'logentry', type_='foreignkey') - op.drop_index('logentry_access_token_id', table_name='logentry') - op.drop_column('logentry', 'access_token_id') + try: + op.drop_constraint(u'fk_logentry_access_token_id_accesstoken', 'logentry', type_='foreignkey') + op.drop_index('logentry_access_token_id', table_name='logentry') + op.drop_column('logentry', 'access_token_id') + except InternalError: + pass ### end Alembic commands ### def downgrade(tables): ### commands auto generated by Alembic - please adjust! ### - op.add_column('logentry', sa.Column('access_token_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True)) - op.create_foreign_key(u'fk_logentry_access_token_id_accesstoken', 'logentry', 'accesstoken', ['access_token_id'], ['id']) - op.create_index('logentry_access_token_id', 'logentry', ['access_token_id'], unique=False) + try: + op.add_column('logentry', sa.Column('access_token_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True)) + op.create_foreign_key(u'fk_logentry_access_token_id_accesstoken', 'logentry', 'accesstoken', ['access_token_id'], ['id']) + op.create_index('logentry_access_token_id', 'logentry', ['access_token_id'], unique=False) + except InternalError: + pass ### end Alembic commands ###