Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/util/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,15 +795,17 @@ def remove_constraint(cr, table, name, cascade=False, warn=True):
"""
_validate_table(table)
log = _logger.warning if warn else _logger.info
cascade = "CASCADE" if cascade else ""
cr.execute('ALTER TABLE "{}" DROP CONSTRAINT IF EXISTS "{}" {}'.format(table, name, cascade))
cascade = SQLStr("CASCADE" if cascade else "")
cr.execute(format_query(cr, "ALTER TABLE {} DROP CONSTRAINT IF EXISTS {} {}", table, name, cascade))
# Exceptionally remove Odoo records, even if we are in PG land on this file. This is somehow
# valid because ir.model.constraint are ORM low-level objects that relate directly to table
# constraints.
cr.execute("DELETE FROM ir_model_constraint WHERE name = %s RETURNING id", [name])
if cr.rowcount:
ids = tuple(c for (c,) in cr.fetchall())
cr.execute("DELETE FROM ir_model_data WHERE model = 'ir.model.constraint' AND res_id IN %s", [ids])
# The constraint was found remove any index with same name
cr.execute(format_query(cr, "DROP INDEX IF EXISTS {}", name))
return True
if name.startswith(table + "_"):
log("%r not found in ir_model_constraint, table=%r", name, table)
Expand Down