fixed issue 1548:Firebird migrations drop column
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.5.1-stable+timestamp.2013.06.22.23.52.14
|
Version 2.5.1-stable+timestamp.2013.06.23.00.14.48
|
||||||
|
|||||||
+31
-33
@@ -1043,16 +1043,16 @@ class BaseAdapter(ConnectionPool):
|
|||||||
elif not key in sql_fields:
|
elif not key in sql_fields:
|
||||||
del sql_fields_current[key]
|
del sql_fields_current[key]
|
||||||
ftype = sql_fields_old[key]['type']
|
ftype = sql_fields_old[key]['type']
|
||||||
if self.dbengine in ('postgres',) \
|
if self.dbengine in ('postgres',) and ftype.startswith('geometry'):
|
||||||
and ftype.startswith('geometry'):
|
|
||||||
geotype, parms = ftype[:-1].split('(')
|
geotype, parms = ftype[:-1].split('(')
|
||||||
schema = parms.split(',')[0]
|
schema = parms.split(',')[0]
|
||||||
query = [ "SELECT DropGeometryColumn ('%(schema)s', '%(table)s', '%(field)s');" % dict(schema=schema, table=tablename, field=key,) ]
|
query = [ "SELECT DropGeometryColumn ('%(schema)s', '%(table)s', '%(field)s');" %
|
||||||
elif not self.dbengine in ('firebird',):
|
dict(schema=schema, table=tablename, field=key,) ]
|
||||||
|
elif self.dbengine in ('firebird',):
|
||||||
|
query = ['ALTER TABLE %s DROP %s;' % (tablename, key)]
|
||||||
|
else:
|
||||||
query = ['ALTER TABLE %s DROP COLUMN %s;'
|
query = ['ALTER TABLE %s DROP COLUMN %s;'
|
||||||
% (tablename, key)]
|
% (tablename, key)]
|
||||||
else:
|
|
||||||
query = ['ALTER TABLE %s DROP %s;' % (tablename, key)]
|
|
||||||
metadata_change = True
|
metadata_change = True
|
||||||
elif sql_fields[key]['sql'] != sql_fields_old[key]['sql'] \
|
elif sql_fields[key]['sql'] != sql_fields_old[key]['sql'] \
|
||||||
and not (key in table.fields and
|
and not (key in table.fields and
|
||||||
@@ -1063,20 +1063,16 @@ class BaseAdapter(ConnectionPool):
|
|||||||
sql_fields_current[key] = sql_fields[key]
|
sql_fields_current[key] = sql_fields[key]
|
||||||
t = tablename
|
t = tablename
|
||||||
tt = sql_fields_aux[key]['sql'].replace(', ', new_add)
|
tt = sql_fields_aux[key]['sql'].replace(', ', new_add)
|
||||||
if not self.dbengine in ('firebird',):
|
if self.dbengine in ('firebird',):
|
||||||
query = ['ALTER TABLE %s ADD %s__tmp %s;' % (t, key, tt),
|
drop_expr = 'ALTER TABLE %s DROP %s;'
|
||||||
'UPDATE %s SET %s__tmp=%s;' % (t, key, key),
|
|
||||||
'ALTER TABLE %s DROP COLUMN %s;' % (t, key),
|
|
||||||
'ALTER TABLE %s ADD %s %s;' % (t, key, tt),
|
|
||||||
'UPDATE %s SET %s=%s__tmp;' % (t, key, key),
|
|
||||||
'ALTER TABLE %s DROP COLUMN %s__tmp;' % (t, key)]
|
|
||||||
else:
|
else:
|
||||||
query = ['ALTER TABLE %s ADD %s__tmp %s;' % (t, key, tt),
|
drop_expr = 'ALTER TABLE %s DROP COLUMN %s;'
|
||||||
'UPDATE %s SET %s__tmp=%s;' % (t, key, key),
|
query = ['ALTER TABLE %s ADD %s__tmp %s;' % (t, key, tt),
|
||||||
'ALTER TABLE %s DROP %s;' % (t, key),
|
'UPDATE %s SET %s__tmp=%s;' % (t, key, key),
|
||||||
'ALTER TABLE %s ADD %s %s;' % (t, key, tt),
|
drop_expr % (t, key),
|
||||||
'UPDATE %s SET %s=%s__tmp;' % (t, key, key),
|
'ALTER TABLE %s ADD %s %s;' % (t, key, tt),
|
||||||
'ALTER TABLE %s DROP %s__tmp;' % (t, key)]
|
'UPDATE %s SET %s=%s__tmp;' % (t, key, key),
|
||||||
|
drop_expr % (t, key)]
|
||||||
metadata_change = True
|
metadata_change = True
|
||||||
elif sql_fields[key]['type'] != sql_fields_old[key]['type']:
|
elif sql_fields[key]['type'] != sql_fields_old[key]['type']:
|
||||||
sql_fields_current[key] = sql_fields[key]
|
sql_fields_current[key] = sql_fields[key]
|
||||||
@@ -1088,30 +1084,32 @@ class BaseAdapter(ConnectionPool):
|
|||||||
db['_lastsql'] = '\n'.join(query)
|
db['_lastsql'] = '\n'.join(query)
|
||||||
for sub_query in query:
|
for sub_query in query:
|
||||||
logfile.write(sub_query + '\n')
|
logfile.write(sub_query + '\n')
|
||||||
if not fake_migrate:
|
if fake_migrate:
|
||||||
|
if db._adapter.commit_on_alter_table:
|
||||||
|
self.save_dbt(table,sql_fields_current)
|
||||||
|
logfile.write('faked!\n')
|
||||||
|
else:
|
||||||
self.execute(sub_query)
|
self.execute(sub_query)
|
||||||
# Caveat: mysql, oracle and firebird do not allow multiple alter table
|
# Caveat: mysql, oracle and firebird do not allow multiple alter table
|
||||||
# in one transaction so we must commit partial transactions and
|
# in one transaction so we must commit partial transactions and
|
||||||
# update table._dbt after alter table.
|
# update table._dbt after alter table.
|
||||||
if db._adapter.commit_on_alter_table:
|
if db._adapter.commit_on_alter_table:
|
||||||
db.commit()
|
db.commit()
|
||||||
tfile = self.file_open(table._dbt, 'w')
|
self.save_dbt(table,sql_fields_current)
|
||||||
pickle.dump(sql_fields_current, tfile)
|
|
||||||
self.file_close(tfile)
|
|
||||||
logfile.write('success!\n')
|
logfile.write('success!\n')
|
||||||
else:
|
|
||||||
logfile.write('faked!\n')
|
|
||||||
elif metadata_change:
|
elif metadata_change:
|
||||||
tfile = self.file_open(table._dbt, 'w')
|
self.save_dbt(table,sql_fields_current)
|
||||||
pickle.dump(sql_fields_current, tfile)
|
|
||||||
self.file_close(tfile)
|
|
||||||
|
|
||||||
if metadata_change and \
|
if metadata_change and not (query and db._adapter.commit_on_alter_table):
|
||||||
not (query and self.dbengine in ('mysql','oracle','firebird')):
|
|
||||||
db.commit()
|
db.commit()
|
||||||
tfile = self.file_open(table._dbt, 'w')
|
self.save_dbt(table,sql_fields_current)
|
||||||
pickle.dump(sql_fields_current, tfile)
|
logfile.write('success!\n')
|
||||||
self.file_close(tfile)
|
|
||||||
|
def save_dbt(self,table, sql_fields_current):
|
||||||
|
tfile = self.file_open(table._dbt, 'w')
|
||||||
|
pickle.dump(sql_fields_current, tfile)
|
||||||
|
self.file_close(tfile)
|
||||||
|
|
||||||
def LOWER(self, first):
|
def LOWER(self, first):
|
||||||
return 'LOWER(%s)' % self.expand(first)
|
return 'LOWER(%s)' % self.expand(first)
|
||||||
|
|||||||
Reference in New Issue
Block a user