Commit bff58e97 authored by Bastian Blank's avatar Bastian Blank

Ignore views for Alembic migrations

parent c6a7e7ec
......@@ -25,6 +25,12 @@ target_metadata = DBConn().db_meta
# ... etc.
def include_object(object, name, type_, reflected, compare_to):
if type_ == "table" and name in DBConn.views:
return False
return True
def run_migrations_offline():
"""Run migrations in 'offline' mode.
......@@ -39,7 +45,11 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True)
url=url,
target_metadata=target_metadata,
literal_binds=True,
include_object=include_object,
)
with context.begin_transaction():
context.run_migrations()
......@@ -60,7 +70,8 @@ def run_migrations_online():
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata
target_metadata=target_metadata,
include_object=include_object,
)
with context.begin_transaction():
......
......@@ -2143,6 +2143,83 @@ class DBConn(object):
tbl_architecture = Architecture.__table__
tables = (
'acl',
'acl_architecture_map',
'acl_fingerprint_map',
'acl_per_source',
'archive',
'bin_associations',
'bin_contents',
'binaries',
'binaries_metadata',
'build_queue',
'changelogs_text',
'changes',
'component',
'component_suite',
'config',
'dsc_files',
'external_files',
'external_overrides',
'external_signature_requests',
'extra_src_references',
'files',
'files_archive_map',
'fingerprint',
'hashfile',
'keyrings',
'maintainer',
'metadata_keys',
'new_comments',
# TODO: the maintainer column in table override should be removed.
'override',
'override_type',
'policy_queue',
'policy_queue_upload',
'policy_queue_upload_binaries_map',
'policy_queue_byhand_file',
'priority',
'signature_history',
'source',
'source_metadata',
'src_associations',
'src_contents',
'src_format',
'src_uploaders',
'suite',
'suite_acl_map',
'suite_architectures',
'suite_build_queue_copy',
'suite_permission',
'suite_src_formats',
'uid',
'version_check',
)
views = (
'almost_obsolete_all_associations',
'almost_obsolete_src_associations',
'any_associations_source',
'bin_associations_binaries',
'binaries_suite_arch',
'changelogs',
'file_arch_suite',
'newest_all_associations',
'newest_any_associations',
'newest_source',
'newest_src_association',
'obsolete_all_associations',
'obsolete_any_associations',
'obsolete_any_by_all_associations',
'obsolete_src_associations',
'package_list',
'source_suite',
'src_associations_bin',
'src_associations_src',
'suite_arch_by_name',
)
def __init__(self, *args, **kwargs):
self.__dict__ = self.__shared_state
......@@ -2152,89 +2229,12 @@ class DBConn(object):
self.__createconn()
def __setuptables(self):
tables = (
'acl',
'acl_architecture_map',
'acl_fingerprint_map',
'acl_per_source',
'archive',
'bin_associations',
'bin_contents',
'binaries',
'binaries_metadata',
'build_queue',
'changelogs_text',
'changes',
'component',
'component_suite',
'config',
'dsc_files',
'external_files',
'external_overrides',
'external_signature_requests',
'extra_src_references',
'files',
'files_archive_map',
'fingerprint',
'hashfile',
'keyrings',
'maintainer',
'metadata_keys',
'new_comments',
# TODO: the maintainer column in table override should be removed.
'override',
'override_type',
'policy_queue',
'policy_queue_upload',
'policy_queue_upload_binaries_map',
'policy_queue_byhand_file',
'priority',
'signature_history',
'source',
'source_metadata',
'src_associations',
'src_contents',
'src_format',
'src_uploaders',
'suite',
'suite_acl_map',
'suite_architectures',
'suite_build_queue_copy',
'suite_permission',
'suite_src_formats',
'uid',
'version_check',
)
views = (
'almost_obsolete_all_associations',
'almost_obsolete_src_associations',
'any_associations_source',
'bin_associations_binaries',
'binaries_suite_arch',
'changelogs',
'file_arch_suite',
'newest_all_associations',
'newest_any_associations',
'newest_source',
'newest_src_association',
'obsolete_all_associations',
'obsolete_any_associations',
'obsolete_any_by_all_associations',
'obsolete_src_associations',
'package_list',
'source_suite',
'src_associations_bin',
'src_associations_src',
'suite_arch_by_name',
)
for table_name in tables:
for table_name in self.tables:
table = Table(table_name, self.db_meta,
autoload=True, useexisting=True)
setattr(self, 'tbl_%s' % table_name, table)
for view_name in views:
for view_name in self.views:
view = Table(view_name, self.db_meta, autoload=True)
setattr(self, 'view_%s' % view_name, view)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment