Fixes #183
This commit is contained in:
parent
40f68278f6
commit
e7bb8245eb
@ -54,3 +54,11 @@ and you would use it like so
|
||||
INFO [alembic.migration] Will assume non-transactional DDL.
|
||||
INFO [alembic.migration] Running upgrade 4358d1b8cc75 -> 1284c81cf727,
|
||||
create lswitch and lswitch port orphaned tables
|
||||
|
||||
|
||||
Workflow for creating a revision
|
||||
================================
|
||||
|
||||
1. Modify quark/db/models.py with your added table/columns.
|
||||
2. Run ``quark-db-manage ... upgrade head``.
|
||||
3. Run ``quark-db-manage ... revision --autogenerate``.
|
||||
|
13
quark/db/migration/alembic/__init__.py
Normal file
13
quark/db/migration/alembic/__init__.py
Normal file
@ -0,0 +1,13 @@
|
||||
from quark.db import models
|
||||
from quark.drivers import optimized_nvp_driver # noqa
|
||||
from quark import quota_driver
|
||||
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
target_metadata = models.BASEV2.metadata
|
||||
# FIXME: https://bitbucket.org/zzzeek/alembic/issue/38
|
||||
table_names = set([tbl.name for tbl in target_metadata.sorted_tables])
|
||||
for t in quota_driver.quota_db.Quota.metadata.tables.values():
|
||||
if t.name == "quotas" and t.name not in table_names:
|
||||
t.tometadata(target_metadata)
|
@ -3,9 +3,7 @@ from alembic import context
|
||||
from sqlalchemy import create_engine, pool
|
||||
from logging import config as logging_config
|
||||
|
||||
from quark.db import models
|
||||
from quark.drivers import optimized_nvp_driver # noqa
|
||||
from quark import quota_driver
|
||||
from quark.db.migration.alembic import target_metadata
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
@ -16,15 +14,6 @@ neutron_config = config.neutron_config
|
||||
# This line sets up loggers basically.
|
||||
logging_config.fileConfig(config.config_file_name)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
target_metadata = models.BASEV2.metadata
|
||||
# FIXME: https://bitbucket.org/zzzeek/alembic/issue/38
|
||||
table_names = set([tbl.name for tbl in target_metadata.sorted_tables])
|
||||
for t in quota_driver.quota_db.Quota.metadata.tables.values():
|
||||
if t.name == "quotas" and t.name not in table_names:
|
||||
t.tometadata(target_metadata)
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
# my_important_option = config.get_main_option("my_important_option")
|
||||
|
@ -18,8 +18,9 @@ def upgrade():
|
||||
op.create_table(
|
||||
'quark_nvp_orphaned_lswitches',
|
||||
sa.Column('id', sa.String(length=36), nullable=False),
|
||||
sa.Column('nvp_id', sa.String(length=36), nullable=True),
|
||||
sa.Column('network_id', sa.String(length=36), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('nvp_id', sa.String(length=36), nullable=False),
|
||||
sa.Column('network_id', sa.String(length=36), nullable=False),
|
||||
sa.Column('display_name', sa.String(length=255), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
mysql_engine='InnoDB')
|
||||
@ -41,7 +42,8 @@ def upgrade():
|
||||
op.create_table(
|
||||
'quark_nvp_orphaned_lswitch_ports',
|
||||
sa.Column('id', sa.String(length=36), nullable=False),
|
||||
sa.Column('port_id', sa.String(length=36), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('port_id', sa.String(length=36), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
mysql_engine='InnoDB')
|
||||
op.create_index(
|
||||
|
@ -19,12 +19,12 @@ def upgrade():
|
||||
sa.Column('enabled',
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default=sa.sql.expression.true()))
|
||||
server_default='1'))
|
||||
op.add_column('quark_mac_address_ranges',
|
||||
sa.Column('do_not_use',
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default=sa.sql.expression.false()))
|
||||
server_default='0'))
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
@ -249,7 +249,8 @@ port_ip_association_table = sa.Table(
|
||||
sa.ForeignKey("quark_ports.id")),
|
||||
sa.Column("ip_address_id", sa.String(36),
|
||||
sa.ForeignKey("quark_ip_addresses.id")),
|
||||
sa.Column("enabled", sa.Boolean(), default=True, nullable=False),
|
||||
sa.Column("enabled", sa.Boolean(), default=True, nullable=False,
|
||||
server_default='1'),
|
||||
**TABLE_KWARGS)
|
||||
|
||||
|
||||
@ -355,7 +356,8 @@ class MacAddressRange(BASEV2, models.HasId):
|
||||
'MacAddress.mac_address_range_id, '
|
||||
'MacAddress.deallocated!=1)',
|
||||
backref="mac_address_range")
|
||||
do_not_use = sa.Column(sa.Boolean(), default=False, nullable=False)
|
||||
do_not_use = sa.Column(sa.Boolean(), default=False, nullable=False,
|
||||
server_default='0')
|
||||
|
||||
|
||||
class IPPolicy(BASEV2, models.HasId, models.HasTenant):
|
||||
|
@ -304,11 +304,11 @@ class SecurityProfile(models.BASEV2, models.HasId):
|
||||
|
||||
class OrphanedLSwitch(models.BASEV2, models.HasId):
|
||||
__tablename__ = "quark_nvp_orphaned_lswitches"
|
||||
nvp_id = sa.Column(sa.String(36))
|
||||
network_id = sa.Column(sa.String(36), index=True)
|
||||
display_name = sa.Column(sa.String(36), index=True)
|
||||
nvp_id = sa.Column(sa.String(36), nullable=False, index=True)
|
||||
network_id = sa.Column(sa.String(36), nullable=False, index=True)
|
||||
display_name = sa.Column(sa.String(255), index=True)
|
||||
|
||||
|
||||
class OrphanedLSwitchPort(models.BASEV2, models.HasId):
|
||||
__tablename__ = "quark_nvp_orphaned_lswitchport"
|
||||
port_id = sa.Column(sa.String(36), index=True)
|
||||
__tablename__ = "quark_nvp_orphaned_lswitch_ports"
|
||||
port_id = sa.Column(sa.String(36), nullable=False, index=True)
|
||||
|
@ -6,6 +6,7 @@ import tempfile
|
||||
from alembic import command as alembic_command
|
||||
from alembic import config as alembic_config
|
||||
import mock
|
||||
from oslo.db.sqlalchemy import test_migrations
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import pool
|
||||
@ -15,6 +16,7 @@ from sqlalchemy.sql import table
|
||||
|
||||
from quark.db.custom_types import INET
|
||||
import quark.db.migration
|
||||
from quark.db.migration.alembic import target_metadata
|
||||
from quark.tests import test_base
|
||||
|
||||
|
||||
@ -29,10 +31,10 @@ class BaseMigrationTest(test_base.TestBase):
|
||||
secret_cfg.database.connection = "sqlite:///" + self.filepath
|
||||
self.config.neutron_config = secret_cfg
|
||||
|
||||
engine = create_engine(
|
||||
self.engine = create_engine(
|
||||
self.config.neutron_config.database.connection,
|
||||
poolclass=pool.NullPool)
|
||||
self.connection = engine.connect()
|
||||
self.connection = self.engine.connect()
|
||||
|
||||
def tearDown(self):
|
||||
self.connection.close()
|
||||
@ -698,3 +700,15 @@ class Test28e55acaf366(BaseMigrationTest):
|
||||
alembic_command.upgrade(self.config, '28e55acaf366')
|
||||
with self.assertRaises(NotImplementedError):
|
||||
alembic_command.downgrade(self.config, '3d22de205729')
|
||||
|
||||
|
||||
class ModelsMigrationsSync(BaseMigrationTest,
|
||||
test_migrations.ModelsMigrationsSync):
|
||||
def get_engine(self):
|
||||
return self.engine
|
||||
|
||||
def db_sync(self, engine):
|
||||
alembic_command.upgrade(self.config, 'head')
|
||||
|
||||
def get_metadata(self):
|
||||
return target_metadata
|
||||
|
@ -7,3 +7,4 @@ python-subunit
|
||||
nose
|
||||
unittest2
|
||||
hacking
|
||||
oslotest
|
||||
|
Loading…
x
Reference in New Issue
Block a user