From 16cd2030aaa86cb040d028a1038daf07e54b19ee Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Tue, 12 Mar 2013 10:03:29 +0100 Subject: [PATCH] Use internal DB management Use our own internal code for managing database migrations, rather than calling sqlalchemy-migrate's command line directly. This allows us to automatically specify the initial version of the database, which is required in order to be able to squash migrations (bug 1072949). Change-Id: I88206f8b55fe6fe4016cee8e5bf1d5eeb0ae30d2 --- bin/heat-db-setup | 3 +-- heat/db/sync.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 heat/db/sync.py diff --git a/bin/heat-db-setup b/bin/heat-db-setup index 56f7165b1e..2b3033bcdd 100755 --- a/bin/heat-db-setup +++ b/bin/heat-db-setup @@ -238,8 +238,7 @@ if [ "${MYSQL_HEAT_PW}" != "${MYSQL_HEAT_PW_DEFAULT}" ] ; then sed -i -e "s/mysql:\/\/heat:\(.*\)@/mysql:\/\/heat:${MYSQL_HEAT_PW}@/" ${HEAT_CONFIG} fi -python -m heat.db.sqlalchemy.manage version_control -python -m heat.db.sqlalchemy.manage upgrade +python -m heat.db.sync # Do a final sanity check on the database. diff --git a/heat/db/sync.py b/heat/db/sync.py new file mode 100644 index 0000000000..96981340e3 --- /dev/null +++ b/heat/db/sync.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import gettext + +import sys + +gettext.install('heat', unicode=1) + +from oslo.config import cfg +from heat.openstack.common import log as logging +import heat.db +from heat.db import migration + + +LOG = logging.getLogger(__name__) + + +if __name__ == '__main__': + cfg.CONF(project='heat', prog='heat-engine') + + heat.db.configure() + + try: + migration.db_sync() + except Exception as exc: + print >>sys.stderr, str(exc) + sys.exit(1)