Use 1/0 as booleans for DB2

DB2 stores booleans as 0 and 1. It does not recognize True/False.

Change-Id: Idaba2fa5bba259e69a1f92c531c3389b3293cf75
Closes-Bug: #1436674
This commit is contained in:
jun xie 2015-03-26 14:18:59 +08:00
parent 1a089e6059
commit bb9b0e01a4
1 changed files with 22 additions and 8 deletions

View 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);')
context = op.get_context()
op.execute('INSERT INTO portsecuritybindings (port_id, '
'port_security_enabled) SELECT id, True FROM ports '
'WHERE id NOT IN (SELECT port_id FROM '
'portsecuritybindings);')
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);')