From 9a74ef71a5f1585872fa0d7e76e755d1cfd212e2 Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Tue, 22 Oct 2013 17:05:56 +0800 Subject: [PATCH] Really fix Alembic migration with SQLite 3. Change-Id: Id02fc70114ad1b78826412cf75af9c7bc3be2cf5 --- debian/changelog | 2 +- ...r_argument_in_add_column_method_call.patch | 18 --- .../fix-alembic-migration-with-sqlite3.patch | 105 ++++++++++++++++++ debian/patches/fix-migration2.patch | 16 --- debian/patches/series | 3 +- 5 files changed, 107 insertions(+), 37 deletions(-) delete mode 100644 debian/patches/Use_proper_argument_in_add_column_method_call.patch create mode 100644 debian/patches/fix-alembic-migration-with-sqlite3.patch delete mode 100644 debian/patches/fix-migration2.patch diff --git a/debian/changelog b/debian/changelog index 55c3d62c9..c5efc65c2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -neutron (2013.2-3) UNRELEASED; urgency=low +neutron (2013.2-3) unstable; urgency=low * Really fix db setup (Closes: #726719). diff --git a/debian/patches/Use_proper_argument_in_add_column_method_call.patch b/debian/patches/Use_proper_argument_in_add_column_method_call.patch deleted file mode 100644 index 7720bfc74..000000000 --- a/debian/patches/Use_proper_argument_in_add_column_method_call.patch +++ /dev/null @@ -1,18 +0,0 @@ -Description: Use proper argument in add_column method call -Author: Eugene Nikanorov -Origin: upstream, https://review.openstack.org/#/c/52636/ -Bug-Debian: http://bugs.debian.org/726719 -Bug-Ubuntu: https://launchpad.net/bugs/1241577 -Last-Update: Fri, 18 Oct 2013 21:50:42 +0800 (17:50 +0400) - ---- neutron-2013.2.orig/neutron/db/migration/alembic_migrations/versions/128e042a2b68_ext_gw_mode.py -+++ neutron-2013.2/neutron/db/migration/alembic_migrations/versions/128e042a2b68_ext_gw_mode.py -@@ -52,7 +52,7 @@ def upgrade(active_plugins=None, options - return - - op.add_column('routers', sa.Column('enable_snat', sa.Boolean(), -- nullable=False, default=True)) -+ nullable=False, server_default='1')) - # Set enable_snat to True for existing routers - op.execute("UPDATE routers SET enable_snat=True") - diff --git a/debian/patches/fix-alembic-migration-with-sqlite3.patch b/debian/patches/fix-alembic-migration-with-sqlite3.patch new file mode 100644 index 000000000..9108b45aa --- /dev/null +++ b/debian/patches/fix-alembic-migration-with-sqlite3.patch @@ -0,0 +1,105 @@ +Description: Replaces Alembic commands by SQLite 3 compatible statements. + SQLite 3 doesn't support the DROP column statement, neither adding a + UNIQUE property on-the-fly. This patch adds the necessary statements to + do it in a SQLite 3 compatible way. +Author: Thomas Goirand +Bug-Debian: http://bugs.debian.org/726719 +Bug-Ubuntu: https://launchpad.net/bugs/1241952 +Forwarded: https://review.openstack.org/#/c/52636 +Last-Update: 2013-10-22 + +--- neutron-2013.2.orig/neutron/db/migration/alembic_migrations/versions/128e042a2b68_ext_gw_mode.py ++++ neutron-2013.2/neutron/db/migration/alembic_migrations/versions/128e042a2b68_ext_gw_mode.py +@@ -52,9 +52,9 @@ def upgrade(active_plugins=None, options + return + + op.add_column('routers', sa.Column('enable_snat', sa.Boolean(), +- nullable=False, default=True)) ++ nullable=False, server_default='1')) + # Set enable_snat to True for existing routers +- op.execute("UPDATE routers SET enable_snat=True") ++ op.execute("UPDATE routers SET enable_snat='True'") + + + def downgrade(active_plugins=None, options=None): +--- neutron-2013.2.orig/neutron/db/migration/alembic_migrations/versions/63afba73813_ovs_tunnelendpoints_id_unique.py ++++ neutron-2013.2/neutron/db/migration/alembic_migrations/versions/63afba73813_ovs_tunnelendpoints_id_unique.py +@@ -46,11 +46,27 @@ def upgrade(active_plugins=None, options + if not migration.should_run(active_plugins, migration_for_plugins): + return + +- op.create_unique_constraint( +- name=CONSTRAINT_NAME, +- source=TABLE_NAME, +- local_cols=['id'] +- ) ++ bind = op.get_bind() ++ engine = bind.engine ++ if engine.name == 'sqlite': ++ op.execute("CREATE TEMPORARY TABLE ovs_tunnel_endpoints_backup ( " ++ "ip_address VARCHAR(64) NOT NULL, " ++ "id INTEGER NOT NULL UNIQUE, " ++ "PRIMARY KEY (ip_address) );") ++ op.execute("INSERT INTO ovs_tunnel_endpoints_backup SELECT ip_address,id FROM ovs_tunnel_endpoints;") ++ op.execute("DROP TABLE ovs_tunnel_endpoints;"); ++ op.execute("CREATE TABLE ovs_tunnel_endpoints ( " ++ "ip_address VARCHAR(64) NOT NULL, " ++ "id INTEGER UNIQUE NOT NULL, " ++ "PRIMARY KEY (ip_address) );") ++ op.execute("INSERT INTO ovs_tunnel_endpoints SELECT ip_address,id FROM ovs_tunnel_endpoints_backup;") ++ op.execute("DROP TABLE ovs_tunnel_endpoints_backup;") ++ else: ++ op.create_unique_constraint( ++ name=CONSTRAINT_NAME, ++ source=TABLE_NAME, ++ local_cols=['id'] ++ ) + + + def downgrade(active_plugins=None, options=None): +--- neutron-2013.2.orig/neutron/db/migration/alembic_migrations/versions/f9263d6df56_remove_dhcp_lease.py ++++ neutron-2013.2/neutron/db/migration/alembic_migrations/versions/f9263d6df56_remove_dhcp_lease.py +@@ -38,7 +38,42 @@ import sqlalchemy as sa + + + def upgrade(active_plugins=None, options=None): +- op.drop_column('ipallocations', u'expiration') ++ bind = op.get_bind() ++ engine = bind.engine ++ if engine.name == 'sqlite': ++ op.execute("CREATE TEMPORARY TABLE ipallocations_backup (" ++ "port_id VARCHAR(36), " ++ "ip_address VARCHAR(64) NOT NULL, " ++ "subnet_id VARCHAR(36) NOT NULL, " ++ "network_id VARCHAR(36) NOT NULL, " ++ "PRIMARY KEY (ip_address, subnet_id, network_id), " ++ "FOREIGN KEY(network_id) REFERENCES networks (id) " ++ "ON DELETE CASCADE, " ++ "FOREIGN KEY(port_id) REFERENCES ports (id) " ++ "ON DELETE CASCADE, " ++ "FOREIGN KEY(subnet_id) REFERENCES subnets (id) " ++ "ON DELETE CASCADE " ++ ");") ++ op.execute("INSERT INTO ipallocations_backup " ++ "SELECT port_id,ip_address,subnet_id,network_id " ++ "FROM ipallocations;") ++ op.execute("DROP TABLE ipallocations;") ++ op.execute("CREATE TABLE ipallocations (" ++ "port_id VARCHAR(36), " ++ "ip_address VARCHAR(64) NOT NULL, " ++ "subnet_id VARCHAR(36) NOT NULL, " ++ "network_id VARCHAR(36) NOT NULL, " ++ "PRIMARY KEY (ip_address, subnet_id, network_id), " ++ "FOREIGN KEY(network_id) REFERENCES networks (id) ON DELETE CASCADE, " ++ "FOREIGN KEY(port_id) REFERENCES ports (id) ON DELETE CASCADE, " ++ "FOREIGN KEY(subnet_id) REFERENCES subnets (id) ON DELETE CASCADE " ++ ");") ++ op.execute("INSERT INTO ipallocations " ++ "SELECT port_id,ip_address,subnet_id,network_id " ++ "FROM ipallocations_backup;") ++ op.execute("DROP TABLE ipallocations_backup;") ++ else: ++ op.drop_column('ipallocations', u'expiration') + + + def downgrade(active_plugins=None, options=None): diff --git a/debian/patches/fix-migration2.patch b/debian/patches/fix-migration2.patch deleted file mode 100644 index bb64e5a5f..000000000 --- a/debian/patches/fix-migration2.patch +++ /dev/null @@ -1,16 +0,0 @@ -Description: Fix miagration2 -Author: Thomas Goirand -Bug-Debian: http://bugs.debian.org/726719 -Last-Update: 2013-10-19 - ---- neutron-2013.2.orig/neutron/db/migration/alembic_migrations/versions/128e042a2b68_ext_gw_mode.py -+++ neutron-2013.2/neutron/db/migration/alembic_migrations/versions/128e042a2b68_ext_gw_mode.py -@@ -54,7 +54,7 @@ def upgrade(active_plugins=None, options - op.add_column('routers', sa.Column('enable_snat', sa.Boolean(), - nullable=False, server_default='1')) - # Set enable_snat to True for existing routers -- op.execute("UPDATE routers SET enable_snat=True") -+ op.execute("UPDATE routers SET enable_snat='True'") - - - def downgrade(active_plugins=None, options=None): diff --git a/debian/patches/series b/debian/patches/series index 11f6e17d1..b4d0c6f9c 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,3 +1,2 @@ better-config-default.patch -Use_proper_argument_in_add_column_method_call.patch -fix-migration2.patch +fix-alembic-migration-with-sqlite3.patch -- 2.45.2