mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Conditionally apply SSOAccountId migration to support misaligned databases
Closes: #34 Signed-off-by: Leonidas Spyropoulos <artafinde@gmail.com>
This commit is contained in:
parent
82f6d2ce75
commit
0d68b914bf
1 changed files with 15 additions and 10 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Reference in a new issue