| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
"""FWaaS router insertion |
| 17 |
|
| 18 |
Revision ID: 540142f314f4 |
| 19 |
Revises: 4202e3047e47 |
| 20 |
Create Date: 2015-02-06 17:02:24.279337 |
| 21 |
|
| 22 |
""" |
| 23 |
|
| 24 |
from alembic import op |
| 25 |
import sqlalchemy as sa |
| 26 |
from sqlalchemy.engine import reflection |
| 27 |
|
| 28 |
|
| 29 |
revision = '540142f314f4' |
| 30 |
down_revision = '4202e3047e47' |
| 31 |
|
| 32 |
SQL_STATEMENT = ( |
| 33 |
"insert into firewall_router_associations " |
| 34 |
"select " |
| 35 |
"f.id as fw_id, r.id as router_id " |
| 36 |
"from firewalls f, routers r " |
| 37 |
"where " |
| 38 |
"f.tenant_id=r.%s" |
| 39 |
) |
| 40 |
|
| 41 |
|
| 42 |
def upgrade(): |
| 43 |
op.create_table('firewall_router_associations', |
| 44 |
sa.Column('fw_id', sa.String(length=36), nullable=False), |
| 45 |
sa.Column('router_id', sa.String( |
| 46 |
length=36), nullable=False), |
| 47 |
sa.ForeignKeyConstraint(['fw_id'], ['firewalls.id'], |
| 48 |
ondelete='CASCADE'), |
| 49 |
sa.ForeignKeyConstraint(['router_id'], ['routers.id'], |
| 50 |
ondelete='CASCADE'), |
| 51 |
sa.PrimaryKeyConstraint('fw_id', 'router_id'), |
| 52 |
) |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
bind = op.get_bind() |
| 58 |
insp = reflection.Inspector.from_engine(bind) |
| 59 |
columns = insp.get_columns('routers') |
| 60 |
if 'tenant_id' in [c['name'] for c in columns]: |
| 61 |
op.execute(SQL_STATEMENT % 'tenant_id') |
| 62 |
else: |
| 63 |
op.execute(SQL_STATEMENT % 'project_id') |