Skip to content

Commit

Permalink
[ADD] delete_constraint_safely: method to delete constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Jul 20, 2022
1 parent a56267a commit dfc16d7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def do_raise(error):
'disable_invalid_filters',
'safe_unlink',
'delete_records_safely_by_xml_id',
'delete_sql_constraint_safely',
'set_xml_ids_noupdate_value',
'convert_to_company_dependent',
'cow_templates_mark_if_equal_to_upstream',
Expand Down Expand Up @@ -2828,6 +2829,25 @@ def delete_records_safely_by_xml_id(env, xml_ids):
logger.info("XML-ID %s changed to noupdate.", xml_id)


def delete_sql_constraint_safely(env, module, table, name):
"""In case of obsolete constraints, run this in pre-migration script.
Useful from v14 onwards.
:param module: Module where the sql constraint was declared
:param table: Table where the sql constraint belongs
:param name: Name of the sql constraint as it was declared"""
logged_query(
env.cr,
"""ALTER TABLE {}
DROP CONSTRAINT IF EXISTS {}""".format(
table, table + "_" + name
),
)
if version_info[0] > 13:
delete_records_safely_by_xml_id(
env, [module + ".constraint_" + table + "_" + name]
)


def chunked(records, single=True):
""" Memory and performance friendly method to iterate over a potentially
large number of records. Yields either a whole chunk or a single record
Expand Down

0 comments on commit dfc16d7

Please sign in to comment.