From 4adc3f13da943e819ad52b212c8ad69edf11bc29 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Sun, 12 May 2013 01:05:51 +0400 Subject: Move get_table() from test_migrations to sqlalchemy.utils get_table() is very useful in different places. So it is better to move it from test_migrations to sqlalchemy.utils. blueprint db-common-migration-and-utils Change-Id: I1191b95aede8688a2b38ac4dd0f2e9108dda1559 --- nova/db/sqlalchemy/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/utils.py b/nova/db/sqlalchemy/utils.py index ccca9cb9d..f0eece661 100644 --- a/nova/db/sqlalchemy/utils.py +++ b/nova/db/sqlalchemy/utils.py @@ -33,6 +33,16 @@ from nova.openstack.common import timeutils LOG = logging.getLogger(__name__) +def get_table(engine, name): + """Returns an sqlalchemy table dynamically from db. + + Needed because the models don't work for us in migrations + as models will be far out of sync with the current data.""" + metadata = MetaData() + metadata.bind = engine + return Table(name, metadata, autoload=True) + + class InsertFromSelect(UpdateBase): def __init__(self, table, select): self.table = table -- cgit