Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sebastien@hermes4:~/DEV/openerp/v61/openobject-server$ bzr diff
- === modified file 'openerp/osv/orm.py'
- --- openerp/osv/orm.py 2011-07-05 12:22:22 +0000
- +++ openerp/osv/orm.py 2011-07-06 23:35:02 +0000
- @@ -2714,6 +2714,233 @@
- cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, column['attname']))
- self.__schema.debug("Table '%s': column '%s': dropped NOT NULL constraint",
- self._table, column['attname'])
- +
- + def update_field(self, cr, create, column_data, k, f, context=None):
- + todo_end=False
- + if isinstance(f, fields.one2many):
- + self._o2m_raise_on_missing_reference(cr, f)
- +
- + elif isinstance(f, fields.many2many):
- + self._m2m_raise_or_create_relation(cr, f)
- +
- + else:
- + res = column_data.get(k)
- +
- + # The field is not found as-is in database, try if it
- + # exists with an old name.
- + if not res and hasattr(f, 'oldname'):
- + res = column_data.get(f.oldname)
- + if res:
- + cr.execute('ALTER TABLE "%s" RENAME "%s" TO "%s"' % (self._table, f.oldname, k))
- + res['attname'] = k
- + column_data[k] = res
- + self.__schema.debug("Table '%s': renamed column '%s' to '%s'",
- + self._table, f.oldname, k)
- +
- + # The field already exists in database. Possibly
- + # change its type, rename it, drop it or change its
- + # constraints.
- + if res:
- + f_pg_type = res['typname']
- + f_pg_size = res['size']
- + f_pg_notnull = res['attnotnull']
- + if isinstance(f, fields.function) and not f.store and\
- + not getattr(f, 'nodrop', False):
- + self.__logger.info('column %s (%s) in table %s removed: converted to a function !\n',
- + k, f.string, self._table)
- + cr.execute('ALTER TABLE "%s" DROP COLUMN "%s" CASCADE' % (self._table, k))
- + cr.commit()
- + self.__schema.debug("Table '%s': dropped column '%s' with cascade",
- + self._table, k)
- + f_obj_type = None
- + else:
- + f_obj_type = get_pg_type(f) and get_pg_type(f)[0]
- +
- + if f_obj_type:
- + ok = False
- + casts = [
- + ('text', 'char', 'VARCHAR(%d)' % (f.size or 0,), '::VARCHAR(%d)'%(f.size or 0,)),
- + ('varchar', 'text', 'TEXT', ''),
- + ('int4', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
- + ('date', 'datetime', 'TIMESTAMP', '::TIMESTAMP'),
- + ('timestamp', 'date', 'date', '::date'),
- + ('numeric', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
- + ('float8', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
- + ]
- + if f_pg_type == 'varchar' and f._type == 'char' and f_pg_size < f.size:
- + cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO temp_change_size' % (self._table, k))
- + cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" VARCHAR(%d)' % (self._table, k, f.size))
- + cr.execute('UPDATE "%s" SET "%s"=temp_change_size::VARCHAR(%d)' % (self._table, k, f.size))
- + cr.execute('ALTER TABLE "%s" DROP COLUMN temp_change_size CASCADE' % (self._table,))
- + cr.commit()
- + self.__schema.debug("Table '%s': column '%s' (type varchar) changed size from %s to %s",
- + self._table, k, f_pg_size, f.size)
- + for c in casts:
- + if (f_pg_type==c[0]) and (f._type==c[1]):
- + if f_pg_type != f_obj_type:
- + ok = True
- + cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO temp_change_size' % (self._table, k))
- + cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, c[2]))
- + cr.execute(('UPDATE "%s" SET "%s"=temp_change_size'+c[3]) % (self._table, k))
- + cr.execute('ALTER TABLE "%s" DROP COLUMN temp_change_size CASCADE' % (self._table,))
- + cr.commit()
- + self.__schema.debug("Table '%s': column '%s' changed type from %s to %s",
- + self._table, k, c[0], c[1])
- + break
- +
- + if f_pg_type != f_obj_type:
- + if not ok:
- + i = 0
- + while True:
- + newname = k + '_moved' + str(i)
- + cr.execute("SELECT count(1) FROM pg_class c,pg_attribute a " \
- + "WHERE c.relname=%s " \
- + "AND a.attname=%s " \
- + "AND c.oid=a.attrelid ", (self._table, newname))
- + if not cr.fetchone()[0]:
- + break
- + i += 1
- + if f_pg_notnull:
- + cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, k))
- + cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO "%s"' % (self._table, k, newname))
- + cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, get_pg_type(f)[1]))
- + cr.execute("COMMENT ON COLUMN %s.%s IS '%s'" % (self._table, k, f.string.replace("'", "''")))
- + self.__schema.debug("Table '%s': column '%s' has changed type (DB=%s, def=%s), data moved to column %s !",
- + self._table, k, f_pg_type, f._type, newname)
- +
- + # if the field is required and hasn't got a NOT NULL constraint
- + if f.required and f_pg_notnull == 0:
- + # set the field to the default value if any
- + if k in self._defaults:
- + if callable(self._defaults[k]):
- + default = self._defaults[k](self, cr, ROOT_USER_ID, context)
- + else:
- + default = self._defaults[k]
- +
- + if (default is not None):
- + ss = self._columns[k]._symbol_set
- + query = 'UPDATE "%s" SET "%s"=%s WHERE "%s" is NULL' % (self._table, k, ss[0], k)
- + cr.execute(query, (ss[1](default),))
- + # add the NOT NULL constraint
- + cr.commit()
- + try:
- + cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k), log_exceptions=False)
- + cr.commit()
- + self.__schema.debug("Table '%s': column '%s': added NOT NULL constraint",
- + self._table, k)
- + except Exception:
- + msg = "Table '%s': unable to set a NOT NULL constraint on column '%s' !\n"\
- + "If you want to have it, you should update the records and execute manually:\n"\
- + "ALTER TABLE %s ALTER COLUMN %s SET NOT NULL"
- + self.__schema.warn(msg, self._table, k, self._table, k)
- + cr.commit()
- + elif not f.required and f_pg_notnull == 1:
- + cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, k))
- + cr.commit()
- + self.__schema.debug("Table '%s': column '%s': dropped NOT NULL constraint",
- + self._table, k)
- + # Verify index
- + indexname = '%s_%s_index' % (self._table, k)
- + cr.execute("SELECT indexname FROM pg_indexes WHERE indexname = %s and tablename = %s", (indexname, self._table))
- + res2 = cr.dictfetchall()
- + if not res2 and f.select:
- + cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (self._table, k, self._table, k))
- + cr.commit()
- + if f._type == 'text':
- + # FIXME: for fields.text columns we should try creating GIN indexes instead (seems most suitable for an ERP context)
- + msg = "Table '%s': Adding (b-tree) index for text column '%s'."\
- + "This is probably useless (does not work for fulltext search) and prevents INSERTs of long texts"\
- + " because there is a length limit for indexable btree values!\n"\
- + "Use a search view instead if you simply want to make the field searchable."
- + self.__schema.warn(msg, self._table, k, f._type)
- + if res2 and not f.select:
- + cr.execute('DROP INDEX "%s_%s_index"' % (self._table, k))
- + cr.commit()
- + msg = "Table '%s': dropping index for column '%s' of type '%s' as it is not required anymore"
- + self.__schema.debug(msg, self._table, k, f._type)
- +
- + if isinstance(f, fields.many2one):
- + ref = self.pool.get(f._obj)._table
- + if ref != 'ir_actions':
- + cr.execute('SELECT confdeltype, conname FROM pg_constraint as con, pg_class as cl1, pg_class as cl2, '
- + 'pg_attribute as att1, pg_attribute as att2 '
- + 'WHERE con.conrelid = cl1.oid '
- + 'AND cl1.relname = %s '
- + 'AND con.confrelid = cl2.oid '
- + 'AND cl2.relname = %s '
- + 'AND array_lower(con.conkey, 1) = 1 '
- + 'AND con.conkey[1] = att1.attnum '
- + 'AND att1.attrelid = cl1.oid '
- + 'AND att1.attname = %s '
- + 'AND array_lower(con.confkey, 1) = 1 '
- + 'AND con.confkey[1] = att2.attnum '
- + 'AND att2.attrelid = cl2.oid '
- + 'AND att2.attname = %s '
- + "AND con.contype = 'f'", (self._table, ref, k, 'id'))
- + res2 = cr.dictfetchall()
- + if res2:
- + if res2[0]['confdeltype'] != POSTGRES_CONFDELTYPES.get(f.ondelete.upper(), 'a'):
- + cr.execute('ALTER TABLE "' + self._table + '" DROP CONSTRAINT "' + res2[0]['conname'] + '"')
- + self._foreign_keys.append((self._table, k, ref, f.ondelete))
- + cr.commit()
- + self.__schema.debug("Table '%s': column '%s': XXX",
- + self._table, k)
- +
- + # The field doesn't exist in database. Create it if necessary.
- + else:
- + if not isinstance(f, fields.function) or f.store:
- + # add the missing field
- + cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, get_pg_type(f)[1]))
- + cr.execute("COMMENT ON COLUMN %s.%s IS '%s'" % (self._table, k, f.string.replace("'", "''")))
- + self.__schema.debug("Table '%s': added column '%s' with definition=%s",
- + self._table, k, get_pg_type(f)[1])
- +
- + # initialize it
- + if not create and k in self._defaults:
- + if callable(self._defaults[k]):
- + default = self._defaults[k](self, cr, ROOT_USER_ID, context)
- + else:
- + default = self._defaults[k]
- +
- + ss = self._columns[k]._symbol_set
- + query = 'UPDATE "%s" SET "%s"=%s' % (self._table, k, ss[0])
- + cr.execute(query, (ss[1](default),))
- + cr.commit()
- + netsvc.Logger().notifyChannel('data', netsvc.LOG_DEBUG, "Table '%s': setting default value of new column %s" % (self._table, k))
- +
- + # remember the functions to call for the stored fields
- + if isinstance(f, fields.function):
- + order = 10
- + if f.store is not True: # i.e. if f.store is a dict
- + order = f.store[f.store.keys()[0]][2]
- + todo_end = (order, self._update_store, (f, k))
- +
- + # and add constraints if needed
- + if isinstance(f, fields.many2one):
- + if not self.pool.get(f._obj):
- + raise except_orm('Programming Error', ('There is no reference available for %s') % (f._obj,))
- + ref = self.pool.get(f._obj)._table
- + # ir_actions is inherited so foreign key doesn't work on it
- + if ref != 'ir_actions':
- + self._foreign_keys.append((self._table, k, ref, f.ondelete))
- + self.__schema.debug("Table '%s': added foreign key '%s' with definition=REFERENCES \"%s\" ON DELETE %s",
- + self._table, k, ref, f.ondelete)
- + if f.select:
- + cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (self._table, k, self._table, k))
- + if f.required:
- + try:
- + cr.commit()
- + cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k), log_exceptions=False)
- + self.__schema.debug("Table '%s': column '%s': added a NOT NULL constraint",
- + self._table, k)
- + except Exception:
- + msg = "WARNING: unable to set column %s of table %s not null !\n"\
- + "Try to re-run: openerp-server --update=module\n"\
- + "If it doesn't work, update records and execute manually:\n"\
- + "ALTER TABLE %s ALTER COLUMN %s SET NOT NULL"
- + self.__logger.warn(msg, k, self._table, self._table, k)
- + cr.commit()
- + return todo_end
- def _auto_init(self, cr, context=None):
- """
- @@ -2739,7 +2966,6 @@
- context = {}
- store_compute = False
- todo_end = []
- - update_custom_fields = context.get('update_custom_fields', False)
- self._field_create(cr, context=context)
- create = not self._table_exist(cr)
- @@ -2766,234 +2992,13 @@
- for k, f in self._columns.iteritems():
- if k in ('id', 'write_uid', 'write_date', 'create_uid', 'create_date'):
- continue
- - # Don't update custom (also called manual) fields
- + # Don't update custom (also called manual) fields
- if f.manual and not update_custom_fields:
- continue
- -
- - if isinstance(f, fields.one2many):
- - self._o2m_raise_on_missing_reference(cr, f)
- -
- - elif isinstance(f, fields.many2many):
- - self._m2m_raise_or_create_relation(cr, f)
- -
- - else:
- - res = column_data.get(k)
- -
- - # The field is not found as-is in database, try if it
- - # exists with an old name.
- - if not res and hasattr(f, 'oldname'):
- - res = column_data.get(f.oldname)
- - if res:
- - cr.execute('ALTER TABLE "%s" RENAME "%s" TO "%s"' % (self._table, f.oldname, k))
- - res['attname'] = k
- - column_data[k] = res
- - self.__schema.debug("Table '%s': renamed column '%s' to '%s'",
- - self._table, f.oldname, k)
- -
- - # The field already exists in database. Possibly
- - # change its type, rename it, drop it or change its
- - # constraints.
- - if res:
- - f_pg_type = res['typname']
- - f_pg_size = res['size']
- - f_pg_notnull = res['attnotnull']
- - if isinstance(f, fields.function) and not f.store and\
- - not getattr(f, 'nodrop', False):
- - self.__logger.info('column %s (%s) in table %s removed: converted to a function !\n',
- - k, f.string, self._table)
- - cr.execute('ALTER TABLE "%s" DROP COLUMN "%s" CASCADE' % (self._table, k))
- - cr.commit()
- - self.__schema.debug("Table '%s': dropped column '%s' with cascade",
- - self._table, k)
- - f_obj_type = None
- - else:
- - f_obj_type = get_pg_type(f) and get_pg_type(f)[0]
- -
- - if f_obj_type:
- - ok = False
- - casts = [
- - ('text', 'char', 'VARCHAR(%d)' % (f.size or 0,), '::VARCHAR(%d)'%(f.size or 0,)),
- - ('varchar', 'text', 'TEXT', ''),
- - ('int4', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
- - ('date', 'datetime', 'TIMESTAMP', '::TIMESTAMP'),
- - ('timestamp', 'date', 'date', '::date'),
- - ('numeric', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
- - ('float8', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
- - ]
- - if f_pg_type == 'varchar' and f._type == 'char' and f_pg_size < f.size:
- - cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO temp_change_size' % (self._table, k))
- - cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" VARCHAR(%d)' % (self._table, k, f.size))
- - cr.execute('UPDATE "%s" SET "%s"=temp_change_size::VARCHAR(%d)' % (self._table, k, f.size))
- - cr.execute('ALTER TABLE "%s" DROP COLUMN temp_change_size CASCADE' % (self._table,))
- - cr.commit()
- - self.__schema.debug("Table '%s': column '%s' (type varchar) changed size from %s to %s",
- - self._table, k, f_pg_size, f.size)
- - for c in casts:
- - if (f_pg_type==c[0]) and (f._type==c[1]):
- - if f_pg_type != f_obj_type:
- - ok = True
- - cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO temp_change_size' % (self._table, k))
- - cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, c[2]))
- - cr.execute(('UPDATE "%s" SET "%s"=temp_change_size'+c[3]) % (self._table, k))
- - cr.execute('ALTER TABLE "%s" DROP COLUMN temp_change_size CASCADE' % (self._table,))
- - cr.commit()
- - self.__schema.debug("Table '%s': column '%s' changed type from %s to %s",
- - self._table, k, c[0], c[1])
- - break
- -
- - if f_pg_type != f_obj_type:
- - if not ok:
- - i = 0
- - while True:
- - newname = k + '_moved' + str(i)
- - cr.execute("SELECT count(1) FROM pg_class c,pg_attribute a " \
- - "WHERE c.relname=%s " \
- - "AND a.attname=%s " \
- - "AND c.oid=a.attrelid ", (self._table, newname))
- - if not cr.fetchone()[0]:
- - break
- - i += 1
- - if f_pg_notnull:
- - cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, k))
- - cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO "%s"' % (self._table, k, newname))
- - cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, get_pg_type(f)[1]))
- - cr.execute("COMMENT ON COLUMN %s.%s IS '%s'" % (self._table, k, f.string.replace("'", "''")))
- - self.__schema.debug("Table '%s': column '%s' has changed type (DB=%s, def=%s), data moved to column %s !",
- - self._table, k, f_pg_type, f._type, newname)
- -
- - # if the field is required and hasn't got a NOT NULL constraint
- - if f.required and f_pg_notnull == 0:
- - # set the field to the default value if any
- - if k in self._defaults:
- - if callable(self._defaults[k]):
- - default = self._defaults[k](self, cr, ROOT_USER_ID, context)
- - else:
- - default = self._defaults[k]
- -
- - if (default is not None):
- - ss = self._columns[k]._symbol_set
- - query = 'UPDATE "%s" SET "%s"=%s WHERE "%s" is NULL' % (self._table, k, ss[0], k)
- - cr.execute(query, (ss[1](default),))
- - # add the NOT NULL constraint
- - cr.commit()
- - try:
- - cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k), log_exceptions=False)
- - cr.commit()
- - self.__schema.debug("Table '%s': column '%s': added NOT NULL constraint",
- - self._table, k)
- - except Exception:
- - msg = "Table '%s': unable to set a NOT NULL constraint on column '%s' !\n"\
- - "If you want to have it, you should update the records and execute manually:\n"\
- - "ALTER TABLE %s ALTER COLUMN %s SET NOT NULL"
- - self.__schema.warn(msg, self._table, k, self._table, k)
- - cr.commit()
- - elif not f.required and f_pg_notnull == 1:
- - cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, k))
- - cr.commit()
- - self.__schema.debug("Table '%s': column '%s': dropped NOT NULL constraint",
- - self._table, k)
- - # Verify index
- - indexname = '%s_%s_index' % (self._table, k)
- - cr.execute("SELECT indexname FROM pg_indexes WHERE indexname = %s and tablename = %s", (indexname, self._table))
- - res2 = cr.dictfetchall()
- - if not res2 and f.select:
- - cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (self._table, k, self._table, k))
- - cr.commit()
- - if f._type == 'text':
- - # FIXME: for fields.text columns we should try creating GIN indexes instead (seems most suitable for an ERP context)
- - msg = "Table '%s': Adding (b-tree) index for text column '%s'."\
- - "This is probably useless (does not work for fulltext search) and prevents INSERTs of long texts"\
- - " because there is a length limit for indexable btree values!\n"\
- - "Use a search view instead if you simply want to make the field searchable."
- - self.__schema.warn(msg, self._table, k, f._type)
- - if res2 and not f.select:
- - cr.execute('DROP INDEX "%s_%s_index"' % (self._table, k))
- - cr.commit()
- - msg = "Table '%s': dropping index for column '%s' of type '%s' as it is not required anymore"
- - self.__schema.debug(msg, self._table, k, f._type)
- -
- - if isinstance(f, fields.many2one):
- - ref = self.pool.get(f._obj)._table
- - if ref != 'ir_actions':
- - cr.execute('SELECT confdeltype, conname FROM pg_constraint as con, pg_class as cl1, pg_class as cl2, '
- - 'pg_attribute as att1, pg_attribute as att2 '
- - 'WHERE con.conrelid = cl1.oid '
- - 'AND cl1.relname = %s '
- - 'AND con.confrelid = cl2.oid '
- - 'AND cl2.relname = %s '
- - 'AND array_lower(con.conkey, 1) = 1 '
- - 'AND con.conkey[1] = att1.attnum '
- - 'AND att1.attrelid = cl1.oid '
- - 'AND att1.attname = %s '
- - 'AND array_lower(con.confkey, 1) = 1 '
- - 'AND con.confkey[1] = att2.attnum '
- - 'AND att2.attrelid = cl2.oid '
- - 'AND att2.attname = %s '
- - "AND con.contype = 'f'", (self._table, ref, k, 'id'))
- - res2 = cr.dictfetchall()
- - if res2:
- - if res2[0]['confdeltype'] != POSTGRES_CONFDELTYPES.get(f.ondelete.upper(), 'a'):
- - cr.execute('ALTER TABLE "' + self._table + '" DROP CONSTRAINT "' + res2[0]['conname'] + '"')
- - self._foreign_keys.append((self._table, k, ref, f.ondelete))
- - cr.commit()
- - self.__schema.debug("Table '%s': column '%s': XXX",
- - self._table, k)
- -
- - # The field doesn't exist in database. Create it if necessary.
- - else:
- - if not isinstance(f, fields.function) or f.store:
- - # add the missing field
- - cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, get_pg_type(f)[1]))
- - cr.execute("COMMENT ON COLUMN %s.%s IS '%s'" % (self._table, k, f.string.replace("'", "''")))
- - self.__schema.debug("Table '%s': added column '%s' with definition=%s",
- - self._table, k, get_pg_type(f)[1])
- -
- - # initialize it
- - if not create and k in self._defaults:
- - if callable(self._defaults[k]):
- - default = self._defaults[k](self, cr, ROOT_USER_ID, context)
- - else:
- - default = self._defaults[k]
- -
- - ss = self._columns[k]._symbol_set
- - query = 'UPDATE "%s" SET "%s"=%s' % (self._table, k, ss[0])
- - cr.execute(query, (ss[1](default),))
- - cr.commit()
- - netsvc.Logger().notifyChannel('data', netsvc.LOG_DEBUG, "Table '%s': setting default value of new column %s" % (self._table, k))
- -
- - # remember the functions to call for the stored fields
- - if isinstance(f, fields.function):
- - order = 10
- - if f.store is not True: # i.e. if f.store is a dict
- - order = f.store[f.store.keys()[0]][2]
- - todo_end.append((order, self._update_store, (f, k)))
- -
- - # and add constraints if needed
- - if isinstance(f, fields.many2one):
- - if not self.pool.get(f._obj):
- - raise except_orm('Programming Error', ('There is no reference available for %s') % (f._obj,))
- - ref = self.pool.get(f._obj)._table
- - # ir_actions is inherited so foreign key doesn't work on it
- - if ref != 'ir_actions':
- - self._foreign_keys.append((self._table, k, ref, f.ondelete))
- - self.__schema.debug("Table '%s': added foreign key '%s' with definition=REFERENCES \"%s\" ON DELETE %s",
- - self._table, k, ref, f.ondelete)
- - if f.select:
- - cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (self._table, k, self._table, k))
- - if f.required:
- - try:
- - cr.commit()
- - cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k), log_exceptions=False)
- - self.__schema.debug("Table '%s': column '%s': added a NOT NULL constraint",
- - self._table, k)
- - except Exception:
- - msg = "WARNING: unable to set column %s of table %s not null !\n"\
- - "Try to re-run: openerp-server --update=module\n"\
- - "If it doesn't work, update records and execute manually:\n"\
- - "ALTER TABLE %s ALTER COLUMN %s SET NOT NULL"
- - self.__logger.warn(msg, k, self._table, self._table, k)
- - cr.commit()
- -
- + todo = self.update_field(cr, create, column_data, k, f, context=context)
- + if todo:
- + todo_end.append(todo)
- +
- else:
- cr.execute("SELECT relname FROM pg_class WHERE relkind IN ('r','v') AND relname=%s", (self._table,))
- create = not bool(cr.fetchone())
Add Comment
Please, Sign In to add comment