Skip to content

Commit

Permalink
Remove DB downgrade
Browse files Browse the repository at this point in the history
As downgrade are not supported after Kilo, we should remove them now.
Roll backs can be performed as mentioned in the below link:
http://docs.openstack.org/ops-guide/ops-upgrades.html#rolling-back-a-failed-upgrade

The DB downgrades were deprecated in Glance Mitaka release by commit
e3366af.

Change-Id: I937d15d93f16a3e44a50e6ff1a469098eab67c79
Implements: blueprint remove-db-downgrade
  • Loading branch information
wangxiyuan committed Sep 1, 2016
1 parent 797a123 commit 2f803d3
Show file tree
Hide file tree
Showing 54 changed files with 51 additions and 1,947 deletions.
9 changes: 5 additions & 4 deletions doc/source/db.rst
Expand Up @@ -53,8 +53,9 @@ This will take an existing database and upgrade it to the specified VERSION.
Downgrading an Existing Database
--------------------------------

glance-manage db downgrade <VERSION>

This will downgrade an existing database from the current version to the
specified VERSION.
Upgrades involve complex operations and can fail. Before attempting any
upgrade, you should make a full database backup of your production data. As of
Kilo, database downgrades are not supported, and the only method available to
get back to a prior database version is to restore from backup[1].

[1]: http://docs.openstack.org/ops-guide/ops-upgrades.html#perform-a-backup
4 changes: 0 additions & 4 deletions doc/source/man/glancemanage.rst
Expand Up @@ -50,10 +50,6 @@ COMMANDS
This will take an existing database and upgrade it to the
specified VERSION.

**db_downgrade <VERSION>**
This will take an existing database and downgrade it to the
specified VERSION.

**db_version_control**
Place the database under migration control.

Expand Down
25 changes: 1 addition & 24 deletions glance/cmd/manage.py
Expand Up @@ -84,17 +84,6 @@ def upgrade(self, version=None):
db_migration.MIGRATE_REPO_PATH,
version)

@args('--version', metavar='<version>', help='Database version')
def downgrade(self, version=None):
"""Downgrade the database's migration level"""
print("Warning: DB downgrade is deprecated and will be removed in N "
"release. Users should make a full database backup of the "
"production data before attempting any upgrade.",
file=sys.stderr)
migration.db_sync(db_api.get_engine(),
db_migration.MIGRATE_REPO_PATH,
version)

@args('--version', metavar='<version>', help='Database version')
def version_control(self, version=None):
"""Place a database under migration control"""
Expand All @@ -107,7 +96,7 @@ def version_control(self, version=None):
help='Current Database version')
def sync(self, version=None, current_version=None):
"""
Place a database under migration control and upgrade/downgrade it,
Place a database under migration control and upgrade it,
creating first if necessary.
"""
if current_version not in (None, 'None'):
Expand Down Expand Up @@ -193,13 +182,6 @@ def version(self):
def upgrade(self, version=None):
self.command_object.upgrade(CONF.command.version)

def downgrade(self, version=None):
print("Warning: DB downgrade is deprecated and will be removed in N "
"release. Users should make a full database backup of the "
"production data before attempting any upgrade.",
file=sys.stderr)
self.command_object.downgrade(CONF.command.version)

def version_control(self, version=None):
self.command_object.version_control(CONF.command.version)

Expand Down Expand Up @@ -234,11 +216,6 @@ def add_legacy_command_parsers(command_object, subparsers):
parser.add_argument('version', nargs='?')
parser.set_defaults(action='db_upgrade')

parser = subparsers.add_parser('db_downgrade')
parser.set_defaults(action_fn=legacy_command_object.downgrade)
parser.add_argument('version')
parser.set_defaults(action='db_downgrade')

parser = subparsers.add_parser('db_version_control')
parser.set_defaults(action_fn=legacy_command_object.version_control)
parser.add_argument('version', nargs='?')
Expand Down
Expand Up @@ -16,7 +16,7 @@
from sqlalchemy.schema import (Column, MetaData, Table)

from glance.db.sqlalchemy.migrate_repo.schema import (
Boolean, DateTime, Integer, String, Text, create_tables, drop_tables) # noqa
Boolean, DateTime, Integer, String, Text, create_tables) # noqa


def define_images_table(meta):
Expand Down Expand Up @@ -53,10 +53,3 @@ def upgrade(migrate_engine):
meta.bind = migrate_engine
tables = [define_images_table(meta)]
create_tables(tables)


def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
tables = [define_images_table(meta)]
drop_tables(tables)
Expand Up @@ -17,7 +17,7 @@
Column, ForeignKey, Index, MetaData, Table, UniqueConstraint)

from glance.db.sqlalchemy.migrate_repo.schema import (
Boolean, DateTime, Integer, String, Text, create_tables, drop_tables,
Boolean, DateTime, Integer, String, Text, create_tables,
from_migration_import) # noqa


Expand Down Expand Up @@ -76,10 +76,3 @@ def upgrade(migrate_engine):
meta.bind = migrate_engine
tables = [define_image_properties_table(meta)]
create_tables(tables)


def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
tables = [define_image_properties_table(meta)]
drop_tables(tables)
44 changes: 0 additions & 44 deletions glance/db/sqlalchemy/migrate_repo/versions/003_add_disk_format.py
Expand Up @@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.

from migrate.changeset import * # noqa
from sqlalchemy import * # noqa

from glance.db.sqlalchemy.migrate_repo.schema import (
Expand Down Expand Up @@ -53,17 +52,6 @@ def get_images_table(meta):
return images


def get_image_properties_table(meta):
"""
No changes to the image properties table from 002...
"""
(define_image_properties_table,) = from_migration_import(
'002_add_image_properties_table', ['define_image_properties_table'])

image_properties = define_image_properties_table(meta)
return image_properties


def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
Expand Down Expand Up @@ -119,35 +107,3 @@ def upgrade(migrate_engine):
container_format.create(images)

images.columns['type'].drop()


def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine

# Steps to take, in this order:
# 1) Add type column back to Image
# 2) Move the existing type properties from ImageProperty into
# Image.type
# 3) Drop the disk_format and container_format columns in Image

conn = migrate_engine.connect()
images = get_images_table(meta)
image_properties = get_image_properties_table(meta)

type_col = Column('type', String(30))
type_col.create(images)

sel = select([image_properties]).where(image_properties.c.key == 'type')
type_property_records = conn.execute(sel).fetchall()
for record in type_property_records:
upd = images.update().where(
images.c.id == record.image_id).values(type=record.value)
conn.execute(upd)
dlt = image_properties.delete().where(
image_properties.c.image_id == record.image_id)
conn.execute(dlt)
conn.close()

images.columns['disk_format'].drop()
images.columns['container_format'].drop()

This file was deleted.

10 changes: 0 additions & 10 deletions glance/db/sqlalchemy/migrate_repo/versions/004_add_checksum.py
Expand Up @@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.

from migrate.changeset import * # noqa
from sqlalchemy import * # noqa

from glance.db.sqlalchemy.migrate_repo.schema import (
Expand Down Expand Up @@ -73,12 +72,3 @@ def upgrade(migrate_engine):

checksum = Column('checksum', String(32))
checksum.create(images)


def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine

images = get_images_table(meta)

images.columns['checksum'].drop()
30 changes: 0 additions & 30 deletions glance/db/sqlalchemy/migrate_repo/versions/005_size_big_integer.py
Expand Up @@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.

from migrate.changeset import * # noqa
from sqlalchemy import * # noqa

from glance.db.sqlalchemy.migrate_repo.schema import (
Expand Down Expand Up @@ -54,17 +53,6 @@ def get_images_table(meta):
return images


def get_image_properties_table(meta):
"""
No changes to the image properties table from 002...
"""
(define_image_properties_table,) = from_migration_import(
'002_add_image_properties_table', ['define_image_properties_table'])

image_properties = define_image_properties_table(meta)
return image_properties


def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
Expand All @@ -84,21 +72,3 @@ def upgrade(migrate_engine):

images = get_images_table(meta)
images.columns['size'].alter(type=BigInteger())


def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine

# No changes to SQLite stores are necessary, since
# there is no BIG INTEGER type in SQLite. Unfortunately,
# running the Python 005_size_big_integer.py migration script
# on a SQLite datastore results in an error in the sa-migrate
# code that does the workarounds for SQLite not having
# ALTER TABLE MODIFY COLUMN ability

dialect = migrate_engine.url.get_dialect().name

if not dialect.startswith('sqlite'):
images = get_images_table(meta)
images.columns['size'].alter(type=Integer())
69 changes: 1 addition & 68 deletions glance/db/sqlalchemy/migrate_repo/versions/006_key_to_name.py
Expand Up @@ -13,11 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.

from migrate.changeset import * # noqa
from sqlalchemy import * # noqa

from glance.db.sqlalchemy.migrate_repo.schema import (
Boolean, DateTime, Integer, String, Text, from_migration_import) # noqa
from glance.db.sqlalchemy.migrate_repo.schema import from_migration_import


def get_images_table(meta):
Expand All @@ -31,44 +29,6 @@ def get_images_table(meta):
return images


def get_image_properties_table(meta):
"""
Returns the Table object for the image_properties table that
corresponds to the image_properties table definition of this version.
"""
(get_images_table,) = from_migration_import(
'004_add_checksum', ['get_images_table'])

images = get_images_table(meta) # noqa

image_properties = Table('image_properties',
meta,
Column('id',
Integer(),
primary_key=True,
nullable=False),
Column('image_id',
Integer(),
ForeignKey('images.id'),
nullable=False,
index=True),
Column('name', String(255), nullable=False),
Column('value', Text()),
Column('created_at', DateTime(), nullable=False),
Column('updated_at', DateTime()),
Column('deleted_at', DateTime()),
Column('deleted',
Boolean(),
nullable=False,
default=False,
index=True),
UniqueConstraint('image_id', 'name'),
mysql_engine='InnoDB',
extend_existing=True)

return image_properties


def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
Expand Down Expand Up @@ -97,30 +57,3 @@ def upgrade(migrate_engine):

image_properties = get_image_properties_table(meta)
image_properties.columns['key'].alter(name="name")


def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine

image_properties = get_image_properties_table(meta)

if migrate_engine.name == "ibm_db_sa":
# NOTE(dperaza) ibm db2 does not allow ALTER INDEX so we will drop
# the index, rename the column, then re-create the index
sql_commands = [
"""ALTER TABLE image_properties DROP UNIQUE
ix_image_properties_image_id_name;""",
"""ALTER TABLE image_properties RENAME COLUMN name to \"key\";""",
"""ALTER TABLE image_properties ADD CONSTRAINT
ix_image_properties_image_id_key UNIQUE(image_id, \"key\");""",
]
for command in sql_commands:
meta.bind.execute(command)
else:
index = Index('ix_image_properties_image_id_name',
image_properties.c.image_id,
image_properties.c.name)
index.rename('ix_image_properties_image_id_key')

image_properties.columns['name'].alter(name="key")

0 comments on commit 2f803d3

Please sign in to comment.