21d431013f
This change proposes the use of Alembic to manage Glance migrations. * Introduce new directory ``alembic_migrations`` under ``glance/db/sqlalchemy``. This directory is the home for all glance migrations henceforth. All the migration scripts reside under ``versions`` directory. * All the migrations up to Liberty are consolidated into one migration called ``liberty_initial`` as those migrations are not supported any more. Mitaka migrations are retained but under a different naming convention. * All the glance manage db commands are changed appropriately. They now use alembic to perform operations such as ``version``, ``upgrade``, ``sync`` and ``version_control``. * The database versions are not numerical any more. They are the revision ID of the last migration applied on the database. Since we don't support migrations before Mitaka, the Liberty version ``42`` will now appear as ``liberty``. Migration ``43`` and ``44`` in Mitaka appear as ``mitaka01`` and ``mitaka02`` respectively. * When one performs a ``sync`` or ``upgrade`` command, the database is first stamped with an equivalent alembic version before upgrading. * The older migration scripts are retained so that users can correlate with the new migrations. Also, it is probably safe to retain them until the alembic migrations become stable. Similarly, the ``migrate_version`` table is not removed yet. Partially-Implements: blueprint alembic-migrations Change-Id: Ie8594ff339a13bf190aefa308f54e97ee20ecfa2 Co-Authored-By: Alexander Bashmakov <alexander.bashmakov@intel.com> Depends-On: I1596499529af249bc48dfe859bbd31e90c48a5e0
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
# Copyright 2010 United States Government as represented by the
|
|
# Administrator of the National Aeronautics and Space Administration.
|
|
# All Rights Reserved.
|
|
#
|
|
# Copyright 2013 OpenStack Foundation
|
|
# Copyright 2013 IBM Corp.
|
|
#
|
|
# 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.
|
|
|
|
"""Database setup and migration commands."""
|
|
|
|
import os
|
|
import threading
|
|
|
|
from oslo_config import cfg
|
|
from oslo_db import options as db_options
|
|
from stevedore import driver
|
|
|
|
from glance.db.sqlalchemy import api as db_api
|
|
|
|
|
|
_IMPL = None
|
|
_LOCK = threading.Lock()
|
|
|
|
db_options.set_defaults(cfg.CONF)
|
|
|
|
|
|
def get_backend():
|
|
global _IMPL
|
|
if _IMPL is None:
|
|
with _LOCK:
|
|
if _IMPL is None:
|
|
_IMPL = driver.DriverManager(
|
|
"glance.database.migration_backend",
|
|
cfg.CONF.database.backend).driver
|
|
return _IMPL
|
|
|
|
ALEMBIC_INIT_VERSION = 'liberty'
|
|
INIT_VERSION = 0
|
|
|
|
MIGRATE_REPO_PATH = os.path.join(
|
|
os.path.abspath(os.path.dirname(__file__)),
|
|
'sqlalchemy',
|
|
'migrate_repo',
|
|
)
|
|
|
|
|
|
def db_sync(version=None, init_version=0, engine=None):
|
|
"""Migrate the database to `version` or the most recent version."""
|
|
|
|
if engine is None:
|
|
engine = db_api.get_engine()
|
|
return get_backend().db_sync(engine=engine,
|
|
abs_path=MIGRATE_REPO_PATH,
|
|
version=version,
|
|
init_version=init_version)
|