Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
# Add foreign key constraint to users table
op.add_column('users', sa.Column('library_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'users', 'library', ['library_id'], ['id'])
op.create_foreign_key('fk_users_library_id', 'users', 'library', ['library_id'], ['id'])

bind = op.get_bind()
# Get all users with link_server in user_data
Expand Down Expand Up @@ -78,6 +78,17 @@ def downgrade():
}
)

op.drop_constraint(None, 'users', type_='foreignkey')
# Find and drop the actual foreign key constraint
bind = op.get_bind()
result = bind.execute("""
SELECT constraint_name
FROM information_schema.table_constraints
WHERE table_name = 'users'
AND constraint_type = 'FOREIGN KEY'
""").fetchone()

if result:
constraint_name = result[0]
op.drop_constraint(constraint_name, 'users', type_='foreignkey')
op.drop_column('users', 'library_id')
# ### end Alembic commands ###