From 26702bac3d0b3f53b8b59191c5f08d4d9cafb1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Wed, 3 Nov 2021 11:46:45 +0100 Subject: [PATCH 1/3] [IMP] project: pre-create computed stored fields --- .../scripts/project/14.0.1.1/pre-migration.py | 20 +++++++++++++++++++ .../14.0.1.1/upgrade_analysis_work.txt | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py index f822ca50ad3..6522c76b574 100644 --- a/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py +++ b/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py @@ -12,6 +12,25 @@ def _set_default_rating_status_period(env): ) +def fast_fill_stored_calculated_fields(env): + """ Faster way """ + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE project_task + ADD COLUMN partner_phone varchar, + ADD COLUMN partner_email varchar""", + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE project_task pt + SET partner_email = rp.email, partner_phone = rp.phone + FROM res_partner rp + WHERE pt.partner_id = rp.id""", + ) + + @openupgrade.migrate() def migrate(env, version): openupgrade.copy_columns( @@ -52,3 +71,4 @@ def migrate(env, version): """CREATE TABLE project_task_res_users_rel (project_task_id INTEGER, res_users_id INTEGER)""", ) + fast_fill_stored_calculated_fields(env) diff --git a/openupgrade_scripts/scripts/project/14.0.1.1/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/project/14.0.1.1/upgrade_analysis_work.txt index c25e7ce4285..5e0fee79e92 100644 --- a/openupgrade_scripts/scripts/project/14.0.1.1/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/project/14.0.1.1/upgrade_analysis_work.txt @@ -37,11 +37,13 @@ project / project.task / allowed_user_ids (many2many) : NEW re # DONE: pre-migration: Pre-create tables for not launching the default + computed # DONE: post-migration: fill these tables from followers +project / project.task / partner_phone (char) : NEW isfunction: function, stored +project / project.task / partner_email (char) : NEW isfunction: function, stored +# DONE: pre-migration: filled by SQL, to avoid computations and inverses + project / project.task / company_id (many2one) : now a function project / project.task / email_from (char) : now a function -project / project.task / partner_email (char) : NEW isfunction: function, stored project / project.task / partner_id (many2one) : now a function -project / project.task / partner_phone (char) : NEW isfunction: function, stored project / project.task / project_id (many2one) : now a function project / project.task / stage_id (many2one) : now a function # NOTHING TO DO: compute methods that will launch when loading From 46d22f40b6c451bcf58f9b539c513e814c94cda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Wed, 3 Nov 2021 12:57:14 +0100 Subject: [PATCH 2/3] [FIX] project: pre-create m2m table --- .../scripts/project/14.0.1.1/pre-migration.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py index 6522c76b574..e8a7271c021 100644 --- a/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py +++ b/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py @@ -66,6 +66,11 @@ def migrate(env, version): """CREATE TABLE project_allowed_internal_users_rel (project_project_id INTEGER, res_users_id INTEGER)""", ) + openupgrade.logged_query( + env.cr, + """CREATE TABLE project_allowed_portal_users_rel + (project_project_id INTEGER, res_users_id INTEGER)""", + ) openupgrade.logged_query( env.cr, """CREATE TABLE project_task_res_users_rel From e1facc0565cc702cecdb4edbc6d54cab24065136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Thu, 11 Nov 2021 19:00:57 +0100 Subject: [PATCH 3/3] [FIX] project: correct m2m table setup --- .../scripts/project/14.0.1.1/post-migration.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openupgrade_scripts/scripts/project/14.0.1.1/post-migration.py b/openupgrade_scripts/scripts/project/14.0.1.1/post-migration.py index 0ce27ca424f..f11d88130f1 100644 --- a/openupgrade_scripts/scripts/project/14.0.1.1/post-migration.py +++ b/openupgrade_scripts/scripts/project/14.0.1.1/post-migration.py @@ -16,6 +16,13 @@ def map_project_project_rating_status(env): def _fill_res_users_m2m_tables(env): # TODO: Take into account channels and task followers part of the old rule + # Remove temp table and re-create m2m table through ORM method + openupgrade.logged_query(env.cr, "DROP TABLE project_allowed_internal_users_rel") + openupgrade.logged_query(env.cr, "DROP TABLE project_allowed_portal_users_rel") + openupgrade.logged_query(env.cr, "DROP TABLE project_task_res_users_rel") + env.registry.init_models( + env.cr, ["project.project", "project.task"], env.context, install=False + ) openupgrade.logged_query( env.cr, """