Skip to content

Commit

Permalink
[FIX] mail: create constrain to avoid migration error when install
Browse files Browse the repository at this point in the history
'to_mail_notif_and_email' module

So in the mail module v16, it has a constrain call
unique_mail_message_id_res_partner_id_if_set, but in the module
'to_mail_notif_and_email' we drop that constains and create a new with
additional condition so when migrating from 15 to 16 it will get error
when registry try to create the constaint.
To avoid that, we should check if the module 'to_mail_notif_and_email'
is installed then instanly create constrain index specify in that module
  • Loading branch information
duong77476-viindoo authored and royle-vietnam committed Jul 19, 2023
1 parent 9b7bab4 commit 45a2859
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions openupgrade_scripts/scripts/mail/16.0.1.10/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ def scheduled_date_set_empty_strings_to_null(env):
)


def _to_mail_notif_and_email_create_mail_notification_index(env):
"""
Only execute this method when module 'to_mail_notif_and_email'
is found and installed to avoid error when init mail module
because it has a constrain that we have overide in 'to_mail_notif_and_email'
if not then we will get error when running migration of mail module
"""
module_to_mail_notif_and_email = env["ir.module.module"].search(
[("name", "=", "to_mail_notif_and_email"), ("state", "=", "to upgrade")]
)
if module_to_mail_notif_and_email:
env.cr.execute(
"""
CREATE UNIQUE INDEX IF NOT EXISTS unique_mail_message_id_res_partner_id_if_set
ON mail_notification (mail_message_id, res_partner_id, notification_type)
WHERE res_partner_id IS NOT NULL
"""
)


@openupgrade.migrate()
def migrate(env, version):
delete_obsolete_constraints(env)
Expand All @@ -98,3 +118,6 @@ def migrate(env, version):
ir_act_server_rename_state_email(env)
mail_channel_channel_type_required(env)
scheduled_date_set_empty_strings_to_null(env)
# This method is only exist in Viindoo/Openupgrade for some
# Technical reason
_to_mail_notif_and_email_create_mail_notification_index(env)

0 comments on commit 45a2859

Please sign in to comment.