Alembic scripts
This commit is contained in:
parent
41f73e2327
commit
f2a7b0829a
|
@ -0,0 +1,99 @@
|
||||||
|
# Copyright 2015 OpenStack Foundation
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
from logging import config as logging_config
|
||||||
|
|
||||||
|
from alembic import context
|
||||||
|
from neutron_lib.db import model_base
|
||||||
|
from oslo_config import cfg
|
||||||
|
from oslo_db.sqlalchemy import session
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy import event
|
||||||
|
|
||||||
|
from neutron.db.migration.alembic_migrations import external
|
||||||
|
from neutron.db.migration.models import head # noqa
|
||||||
|
|
||||||
|
MYSQL_ENGINE = None
|
||||||
|
WANTC_VERSION_TABLE = 'wantc_alembic_version'
|
||||||
|
config = context.config
|
||||||
|
neutron_config = config.neutron_config
|
||||||
|
logging_config.fileConfig(config.config_file_name)
|
||||||
|
target_metadata = model_base.BASEV2.metadata
|
||||||
|
|
||||||
|
|
||||||
|
def set_mysql_engine():
|
||||||
|
try:
|
||||||
|
mysql_engine = neutron_config.command.mysql_engine
|
||||||
|
except cfg.NoSuchOptError:
|
||||||
|
mysql_engine = None
|
||||||
|
|
||||||
|
global MYSQL_ENGINE
|
||||||
|
MYSQL_ENGINE = (mysql_engine or
|
||||||
|
model_base.BASEV2.__table_args__['mysql_engine'])
|
||||||
|
|
||||||
|
|
||||||
|
def include_object(object, name, type_, reflected, compare_to):
|
||||||
|
if type_ == 'table' and name in external.TABLES:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def run_migrations_offline():
|
||||||
|
set_mysql_engine()
|
||||||
|
|
||||||
|
kwargs = dict()
|
||||||
|
if neutron_config.database.connection:
|
||||||
|
kwargs['url'] = neutron_config.database.connection
|
||||||
|
else:
|
||||||
|
kwargs['dialect_name'] = neutron_config.database.engine
|
||||||
|
kwargs['include_object'] = include_object
|
||||||
|
kwargs['version_table'] = WANTC_VERSION_TABLE
|
||||||
|
context.configure(**kwargs)
|
||||||
|
|
||||||
|
with context.begin_transaction():
|
||||||
|
context.run_migrations()
|
||||||
|
|
||||||
|
|
||||||
|
@event.listens_for(sa.Table, 'after_parent_attach')
|
||||||
|
def set_storage_engine(target, parent):
|
||||||
|
if MYSQL_ENGINE:
|
||||||
|
target.kwargs['mysql_engine'] = MYSQL_ENGINE
|
||||||
|
|
||||||
|
|
||||||
|
def run_migrations_online():
|
||||||
|
set_mysql_engine()
|
||||||
|
engine = session.create_engine(neutron_config.database.connection)
|
||||||
|
|
||||||
|
connection = engine.connect()
|
||||||
|
context.configure(
|
||||||
|
connection=connection,
|
||||||
|
target_metadata=target_metadata,
|
||||||
|
include_object=include_object,
|
||||||
|
version_table=WANTC_VERSION_TABLE
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with context.begin_transaction():
|
||||||
|
context.run_migrations()
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
engine.dispose()
|
||||||
|
|
||||||
|
|
||||||
|
if context.is_offline_mode():
|
||||||
|
run_migrations_offline()
|
||||||
|
else:
|
||||||
|
run_migrations_online()
|
|
@ -0,0 +1,36 @@
|
||||||
|
# Copyright ${create_date.year} <PUT YOUR NAME/COMPANY HERE>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""${message}
|
||||||
|
|
||||||
|
Revision ID: ${up_revision}
|
||||||
|
Revises: ${down_revision}
|
||||||
|
Create Date: ${create_date}
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = ${repr(up_revision)}
|
||||||
|
down_revision = ${repr(down_revision)}
|
||||||
|
% if branch_labels:
|
||||||
|
branch_labels = ${repr(branch_labels)}
|
||||||
|
%endif
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
${imports if imports else ""}
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
${upgrades if upgrades else "pass"}
|
|
@ -0,0 +1,63 @@
|
||||||
|
# Copyright 2017 <PUT YOUR NAME/COMPANY HERE>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""first rev
|
||||||
|
|
||||||
|
Revision ID: 45194b1d3492
|
||||||
|
Revises: None
|
||||||
|
Create Date: 2017-01-04 13:46:13.433909
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '45194b1d3492'
|
||||||
|
down_revision = None
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_table('wan_tc_class',
|
||||||
|
sa.Column('id', sa.String(length=36), nullable=False),
|
||||||
|
sa.Column('networks_id', sa.String(length=36),
|
||||||
|
nullable=False),
|
||||||
|
sa.Column('class_ext_id', sa.Integer()),
|
||||||
|
sa.Column('min_rate',
|
||||||
|
sa.String(length=15), nullable=False),
|
||||||
|
sa.Column('min_rate', sa.String(length=15)),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
|
||||||
|
op.create_foreign_key(
|
||||||
|
'fk_wan_tc_class_networks',
|
||||||
|
'wan_tc_class', 'networks',
|
||||||
|
['networks_id'], ['id'],
|
||||||
|
)
|
||||||
|
|
||||||
|
op.create_table('wan_tc_selector',
|
||||||
|
sa.Column('id', sa.String(length=36), nullable=False),
|
||||||
|
sa.Column('class_id', sa.String(length=36),
|
||||||
|
nullable=False),
|
||||||
|
sa.Column('protocol', sa.String(length=15)),
|
||||||
|
sa.Column('match', sa.String(length=15)),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
|
||||||
|
op.create_foreign_key(
|
||||||
|
'fk_wan_tc__selector_class',
|
||||||
|
'wan_tc_selector', 'wan_tc_class',
|
||||||
|
['class_id'], ['id'],
|
||||||
|
)
|
|
@ -28,9 +28,7 @@ class WanTcClass(model_base.BASEV2,
|
||||||
network_id = sa.Column(sa.String(36),
|
network_id = sa.Column(sa.String(36),
|
||||||
sa.ForeignKey('networks.id',
|
sa.ForeignKey('networks.id',
|
||||||
ondelete='CASCADE'),
|
ondelete='CASCADE'),
|
||||||
nullable=False,
|
nullable=False)
|
||||||
unique=True,
|
|
||||||
primary_key=True)
|
|
||||||
min_rate = sa.Column(sa.String(15), nullable=False)
|
min_rate = sa.Column(sa.String(15), nullable=False)
|
||||||
max_rate = sa.Column(sa.String(15))
|
max_rate = sa.Column(sa.String(15))
|
||||||
|
|
||||||
|
@ -41,8 +39,7 @@ class WanTcSelector(model_base.BASEV2,
|
||||||
class_id = sa.Column(sa.String(36),
|
class_id = sa.Column(sa.String(36),
|
||||||
sa.ForeignKey('wan_tc_class.id',
|
sa.ForeignKey('wan_tc_class.id',
|
||||||
ondelete='CASCADE'),
|
ondelete='CASCADE'),
|
||||||
nullable=False,
|
nullable=False)
|
||||||
primary_key=True)
|
|
||||||
protocol = sa.Column(sa.String(15))
|
protocol = sa.Column(sa.String(15))
|
||||||
match = sa.Column(sa.String(15))
|
match = sa.Column(sa.String(15))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue