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] Will assume non-transactional DDL.
|
||||||
INFO [alembic.migration] Running upgrade 4358d1b8cc75 -> 1284c81cf727,
|
INFO [alembic.migration] Running upgrade 4358d1b8cc75 -> 1284c81cf727,
|
||||||
create lswitch and lswitch port orphaned tables
|
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 sqlalchemy import create_engine, pool
|
||||||
from logging import config as logging_config
|
from logging import config as logging_config
|
||||||
|
|
||||||
from quark.db import models
|
from quark.db.migration.alembic import target_metadata
|
||||||
from quark.drivers import optimized_nvp_driver # noqa
|
|
||||||
from quark import quota_driver
|
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
# this is the Alembic Config object, which provides
|
||||||
# access to the values within the .ini file in use.
|
# 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.
|
# This line sets up loggers basically.
|
||||||
logging_config.fileConfig(config.config_file_name)
|
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,
|
# other values from the config, defined by the needs of env.py,
|
||||||
# can be acquired:
|
# can be acquired:
|
||||||
# my_important_option = config.get_main_option("my_important_option")
|
# my_important_option = config.get_main_option("my_important_option")
|
||||||
|
@ -18,8 +18,9 @@ def upgrade():
|
|||||||
op.create_table(
|
op.create_table(
|
||||||
'quark_nvp_orphaned_lswitches',
|
'quark_nvp_orphaned_lswitches',
|
||||||
sa.Column('id', sa.String(length=36), nullable=False),
|
sa.Column('id', sa.String(length=36), nullable=False),
|
||||||
sa.Column('nvp_id', sa.String(length=36), nullable=True),
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('network_id', sa.String(length=36), 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.Column('display_name', sa.String(length=255), nullable=True),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
mysql_engine='InnoDB')
|
mysql_engine='InnoDB')
|
||||||
@ -41,7 +42,8 @@ def upgrade():
|
|||||||
op.create_table(
|
op.create_table(
|
||||||
'quark_nvp_orphaned_lswitch_ports',
|
'quark_nvp_orphaned_lswitch_ports',
|
||||||
sa.Column('id', sa.String(length=36), nullable=False),
|
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'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
mysql_engine='InnoDB')
|
mysql_engine='InnoDB')
|
||||||
op.create_index(
|
op.create_index(
|
||||||
|
@ -19,12 +19,12 @@ def upgrade():
|
|||||||
sa.Column('enabled',
|
sa.Column('enabled',
|
||||||
sa.Boolean(),
|
sa.Boolean(),
|
||||||
nullable=False,
|
nullable=False,
|
||||||
server_default=sa.sql.expression.true()))
|
server_default='1'))
|
||||||
op.add_column('quark_mac_address_ranges',
|
op.add_column('quark_mac_address_ranges',
|
||||||
sa.Column('do_not_use',
|
sa.Column('do_not_use',
|
||||||
sa.Boolean(),
|
sa.Boolean(),
|
||||||
nullable=False,
|
nullable=False,
|
||||||
server_default=sa.sql.expression.false()))
|
server_default='0'))
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
@ -249,7 +249,8 @@ port_ip_association_table = sa.Table(
|
|||||||
sa.ForeignKey("quark_ports.id")),
|
sa.ForeignKey("quark_ports.id")),
|
||||||
sa.Column("ip_address_id", sa.String(36),
|
sa.Column("ip_address_id", sa.String(36),
|
||||||
sa.ForeignKey("quark_ip_addresses.id")),
|
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)
|
**TABLE_KWARGS)
|
||||||
|
|
||||||
|
|
||||||
@ -355,7 +356,8 @@ class MacAddressRange(BASEV2, models.HasId):
|
|||||||
'MacAddress.mac_address_range_id, '
|
'MacAddress.mac_address_range_id, '
|
||||||
'MacAddress.deallocated!=1)',
|
'MacAddress.deallocated!=1)',
|
||||||
backref="mac_address_range")
|
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):
|
class IPPolicy(BASEV2, models.HasId, models.HasTenant):
|
||||||
|
@ -304,11 +304,11 @@ class SecurityProfile(models.BASEV2, models.HasId):
|
|||||||
|
|
||||||
class OrphanedLSwitch(models.BASEV2, models.HasId):
|
class OrphanedLSwitch(models.BASEV2, models.HasId):
|
||||||
__tablename__ = "quark_nvp_orphaned_lswitches"
|
__tablename__ = "quark_nvp_orphaned_lswitches"
|
||||||
nvp_id = sa.Column(sa.String(36))
|
nvp_id = sa.Column(sa.String(36), nullable=False, index=True)
|
||||||
network_id = sa.Column(sa.String(36), index=True)
|
network_id = sa.Column(sa.String(36), nullable=False, index=True)
|
||||||
display_name = sa.Column(sa.String(36), index=True)
|
display_name = sa.Column(sa.String(255), index=True)
|
||||||
|
|
||||||
|
|
||||||
class OrphanedLSwitchPort(models.BASEV2, models.HasId):
|
class OrphanedLSwitchPort(models.BASEV2, models.HasId):
|
||||||
__tablename__ = "quark_nvp_orphaned_lswitchport"
|
__tablename__ = "quark_nvp_orphaned_lswitch_ports"
|
||||||
port_id = sa.Column(sa.String(36), index=True)
|
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 command as alembic_command
|
||||||
from alembic import config as alembic_config
|
from alembic import config as alembic_config
|
||||||
import mock
|
import mock
|
||||||
|
from oslo.db.sqlalchemy import test_migrations
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy import pool
|
from sqlalchemy import pool
|
||||||
@ -15,6 +16,7 @@ from sqlalchemy.sql import table
|
|||||||
|
|
||||||
from quark.db.custom_types import INET
|
from quark.db.custom_types import INET
|
||||||
import quark.db.migration
|
import quark.db.migration
|
||||||
|
from quark.db.migration.alembic import target_metadata
|
||||||
from quark.tests import test_base
|
from quark.tests import test_base
|
||||||
|
|
||||||
|
|
||||||
@ -29,10 +31,10 @@ class BaseMigrationTest(test_base.TestBase):
|
|||||||
secret_cfg.database.connection = "sqlite:///" + self.filepath
|
secret_cfg.database.connection = "sqlite:///" + self.filepath
|
||||||
self.config.neutron_config = secret_cfg
|
self.config.neutron_config = secret_cfg
|
||||||
|
|
||||||
engine = create_engine(
|
self.engine = create_engine(
|
||||||
self.config.neutron_config.database.connection,
|
self.config.neutron_config.database.connection,
|
||||||
poolclass=pool.NullPool)
|
poolclass=pool.NullPool)
|
||||||
self.connection = engine.connect()
|
self.connection = self.engine.connect()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
@ -698,3 +700,15 @@ class Test28e55acaf366(BaseMigrationTest):
|
|||||||
alembic_command.upgrade(self.config, '28e55acaf366')
|
alembic_command.upgrade(self.config, '28e55acaf366')
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
alembic_command.downgrade(self.config, '3d22de205729')
|
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
|
nose
|
||||||
unittest2
|
unittest2
|
||||||
hacking
|
hacking
|
||||||
|
oslotest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user