summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Prince <dprince@redhat.com>2012-11-19 11:53:23 -0500
committerDan Prince <dprince@redhat.com>2012-11-19 11:57:32 -0500
commit8e9e5c7965d50113dda4e69c9ec0248cd3db0037 (patch)
tree253df713da95cdf54ee3685c18bde0813dfcd2a4
parentcce0428ab51484564d0f17e3013367e4c0028873 (diff)
downloadnova-8e9e5c7965d50113dda4e69c9ec0248cd3db0037.tar.gz
nova-8e9e5c7965d50113dda4e69c9ec0248cd3db0037.tar.xz
nova-8e9e5c7965d50113dda4e69c9ec0248cd3db0037.zip
Drop unused PostgreSQL sequences from Folsom.
In Folsom the snapshots and volumes tables were converted to use UUID's. When we performed this conversion in Folsom a couple of unused PostgreSQL sequences were left behind. This migration removes the snapshots_id_seq and volumes_id_seq if they exist in the schema when using PostgreSQL. Fixes LP Bug #1080786. Change-Id: I075e2afebcb5236f96ab5d6ab13e249d078da86b
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/140_drop_unused_postgresql_volume_sequences.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/140_drop_unused_postgresql_volume_sequences.py b/nova/db/sqlalchemy/migrate_repo/versions/140_drop_unused_postgresql_volume_sequences.py
new file mode 100644
index 000000000..18aa206fe
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/140_drop_unused_postgresql_volume_sequences.py
@@ -0,0 +1,61 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2012 Red Hat, Inc.
+# All Rights Reserved.
+#
+# 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.
+
+from sqlalchemy import MetaData
+
+
+def upgrade(migrate_engine):
+ meta = MetaData()
+ meta.bind = migrate_engine
+
+ # NOTE(dprince): Remove unused snapshots/volumes sequences.
+ # These are leftovers from the ID --> UUID conversion for these tables
+ # that occurred in Folsom.
+ if migrate_engine.name == "postgresql":
+ base_query = """SELECT COUNT(*) FROM pg_class c
+ WHERE c.relkind = 'S'
+ AND relname = '%s';"""
+ result = migrate_engine.execute(base_query % "snapshots_id_seq")
+ if result.scalar() > 0:
+ sql = "DROP SEQUENCE snapshots_id_seq CASCADE;"
+ migrate_engine.execute(sql)
+
+ result = migrate_engine.execute(base_query % "volumes_id_seq")
+ if result.scalar() > 0:
+ sql = "DROP SEQUENCE volumes_id_seq CASCADE;"
+ migrate_engine.execute(sql)
+
+
+def downgrade(migrate_engine):
+ meta = MetaData()
+ meta.bind = migrate_engine
+
+ if migrate_engine.name == "postgresql":
+ sql = """CREATE SEQUENCE snapshots_id_seq START WITH 1 INCREMENT BY 1
+ NO MINVALUE NO MAXVALUE CACHE 1;
+ ALTER SEQUENCE snapshots_id_seq OWNED BY snapshots.id;
+ SELECT pg_catalog.setval('snapshots_id_seq', 1, false);
+ ALTER TABLE ONLY snapshots ALTER COLUMN id SET DEFAULT
+ nextval('snapshots_id_seq'::regclass);"""
+
+ sql += """CREATE SEQUENCE volumes_id_seq START WITH 1 INCREMENT BY 1
+ NO MINVALUE NO MAXVALUE CACHE 1;
+ ALTER SEQUENCE volumes_id_seq OWNED BY volumes.id;
+ SELECT pg_catalog.setval('volumes_id_seq', 1, false);
+ ALTER TABLE ONLY volumes ALTER COLUMN id SET DEFAULT
+ nextval('volumes_id_seq'::regclass);"""
+ migrate_engine.execute(sql)