]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use 1/0 as booleans for DB2
authorjun xie <easonxie160@163.com>
Thu, 26 Mar 2015 06:18:59 +0000 (14:18 +0800)
committerjun xie <easonxie160@163.com>
Thu, 26 Mar 2015 06:22:16 +0000 (14:22 +0800)
DB2 stores booleans as 0 and 1. It does not recognize True/False.

Change-Id: Idaba2fa5bba259e69a1f92c531c3389b3293cf75
Closes-Bug: #1436674

neutron/db/migration/alembic_migrations/versions/35a0f3365720_add_port_security_in_ml2.py

index 1b6bc60ac570cc482d609c7f7323acc3a629d59f..82bd40324e47c65ec0b04e02eb6733c4be77c289 100644 (file)
@@ -29,12 +29,26 @@ from alembic import op
 
 
 def upgrade():
-    op.execute('INSERT INTO networksecuritybindings (network_id, '
-               'port_security_enabled) SELECT id, True FROM networks '
-               'WHERE id NOT IN (SELECT network_id FROM '
-               'networksecuritybindings);')
-
-    op.execute('INSERT INTO portsecuritybindings (port_id, '
-               'port_security_enabled) SELECT id, True FROM ports '
-               'WHERE id NOT IN (SELECT port_id FROM '
-               'portsecuritybindings);')
+    context = op.get_context()
+
+    if context.bind.dialect.name == 'ibm_db_sa':
+        # NOTE(junxie): DB2 stores booleans as 0 and 1.
+        op.execute('INSERT INTO networksecuritybindings (network_id, '
+                   'port_security_enabled) SELECT id, 1 FROM networks '
+                   'WHERE id NOT IN (SELECT network_id FROM '
+                   'networksecuritybindings);')
+
+        op.execute('INSERT INTO portsecuritybindings (port_id, '
+                   'port_security_enabled) SELECT id, 1 FROM ports '
+                   'WHERE id NOT IN (SELECT port_id FROM '
+                   'portsecuritybindings);')
+    else:
+        op.execute('INSERT INTO networksecuritybindings (network_id, '
+                   'port_security_enabled) SELECT id, True FROM networks '
+                   'WHERE id NOT IN (SELECT network_id FROM '
+                   'networksecuritybindings);')
+
+        op.execute('INSERT INTO portsecuritybindings (port_id, '
+                   'port_security_enabled) SELECT id, True FROM ports '
+                   'WHERE id NOT IN (SELECT port_id FROM '
+                   'portsecuritybindings);')