# Path: networking_bgpvpn/neutron/db/head.py
# def get_metadata():


from oslo_config import cfg
from neutron.db.migration.alembic_migrations import external
from neutron.db.migration import cli as migration
from neutron.tests.functional.db import test_migrations
from neutron.tests.unit import testlib_api
from networking_bgpvpn.neutron.db import head
# Tables from other repos that we depend on but do not manage.
IGNORED_TABLES_MATCH = (
    'ml2_route_target_allocations',
    '_bagpipe_',
)

# EXTERNAL_TABLES should contain all names of tables that are not related to
# current repo.
EXTERNAL_TABLES = set(external.TABLES)
VERSION_TABLE = 'alembic_version_bgpvpn'


class _TestModelsMigrationsBGPVPN(test_migrations._TestModelsMigrations):

    def db_sync(self, engine):
        cfg.CONF.set_override('connection', engine.url, group='database')
        for conf in migration.get_alembic_configs():
            self.alembic_config = conf
            self.alembic_config.neutron_config = cfg.CONF
            migration.do_alembic_command(conf, 'upgrade', 'heads')

    def get_metadata(self):
        return head.get_metadata()

    def include_object(self, object_, name, type_, reflected, compare_to):
        if (type_ == "table" and (
            name.startswith("alembic") or
            name == VERSION_TABLE or
            name in EXTERNAL_TABLES or
            any([match in name for match in IGNORED_TABLES_MATCH])

# Path: networking_bgpvpn/neutron/db/head.py
# def get_metadata():


# Path: networking_bgpvpn/tests/functional/db/test_migrations.py
from oslo_config import cfg
from neutron.db.migration.alembic_migrations import external
from neutron.db.migration import cli as migration
from neutron.tests.functional.db import test_migrations
from neutron.tests.unit import testlib_api
from networking_bgpvpn.neutron.db import head

# Tables from other repos that we depend on but do not manage.
IGNORED_TABLES_MATCH = (
    'ml2_route_target_allocations',
    '_bagpipe_',
)

# EXTERNAL_TABLES should contain all names of tables that are not related to
# current repo.
EXTERNAL_TABLES = set(external.TABLES)
VERSION_TABLE = 'alembic_version_bgpvpn'


class _TestModelsMigrationsBGPVPN(test_migrations._TestModelsMigrations):

    def db_sync(self, engine):
        cfg.CONF.set_override('connection', engine.url, group='database')
        for conf in migration.get_alembic_configs():
            self.alembic_config = conf
            self.alembic_config.neutron_config = cfg.CONF
            migration.do_alembic_command(conf, 'upgrade', 'heads')

    def get_metadata(self):
        return head.get_metadata()

    def include_object(self, object_, name, type_, reflected, compare_to):
        if (type_ == "table" and (
            name.startswith("alembic") or
            name == VERSION_TABLE or
            name in EXTERNAL_TABLES or
            any([match in name for match in IGNORED_TABLES_MATCH])

        )):