Skip to content
Snippets Groups Projects
Commit 0d68b914 authored by Leonidas Spyropoulos's avatar Leonidas Spyropoulos Committed by Kevin Morris
Browse files

Conditionally apply SSOAccountId migration to support misaligned databases


Closes: #34

Signed-off-by: default avatarLeonidas Spyropoulos <artafinde@gmail.com>
parent 82f6d2ce
Branches bert
No related tags found
No related merge requests found
......@@ -5,9 +5,9 @@ Revises: f47cad5d6d03
Create Date: 2020-06-08 10:04:13.898617
"""
from alembic import op
import sqlalchemy as sa
from alembic import op
from sqlalchemy.engine.reflection import Inspector
# revision identifiers, used by Alembic.
revision = 'ef39fcd6e1cd'
......@@ -16,15 +16,20 @@ branch_labels = None
depends_on = None
def table_has_column(table, column_name):
for element in Inspector.from_engine(op.get_bind()).get_columns(table):
if element.get('name') == column_name:
return True
return False
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('Users', sa.Column('SSOAccountID', sa.String(length=255), nullable=True))
op.create_unique_constraint(None, 'Users', ['SSOAccountID'])
# ### end Alembic commands ###
if not table_has_column('Users', 'SSOAccountID'):
op.add_column('Users', sa.Column('SSOAccountID', sa.String(length=255), nullable=True))
op.create_unique_constraint(None, 'Users', ['SSOAccountID'])
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('SSOAccountID', 'Users', type_='unique')
op.drop_column('Users', 'SSOAccountID')
# ### end Alembic commands ###
if table_has_column('Users', 'SSOAccountID'):
op.drop_constraint('SSOAccountID', 'Users', type_='unique')
op.drop_column('Users', 'SSOAccountID')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment