From 136f7d63e9a51bc59fc2b99dbe13ed203ac461ef Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 4 Jul 2023 21:37:35 +0200 Subject: [PATCH] [OU-ADD] website_event_questions: Migration scripts TT42044 --- docsource/modules140-150.rst | 2 +- .../15.0.1.2/noupdate_changes.xml | 4 +-- .../15.0.1.2/post-migration.py | 29 +++++++++++++++++++ .../15.0.1.2/pre-migration.py | 28 ++++++++++++++++++ .../15.0.1.2/upgrade_analysis_work.txt | 21 ++++++++++++++ 5 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 openupgrade_scripts/scripts/website_event_questions/15.0.1.2/post-migration.py create mode 100644 openupgrade_scripts/scripts/website_event_questions/15.0.1.2/pre-migration.py create mode 100644 openupgrade_scripts/scripts/website_event_questions/15.0.1.2/upgrade_analysis_work.txt diff --git a/docsource/modules140-150.rst b/docsource/modules140-150.rst index fd94f8b63b32..323c0719a7da 100644 --- a/docsource/modules140-150.rst +++ b/docsource/modules140-150.rst @@ -794,7 +794,7 @@ Module coverage 14.0 -> 15.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | website_event_meet_quiz | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| website_event_questions | | | +| website_event_questions | Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | website_event_sale | Nothing to do | | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/noupdate_changes.xml b/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/noupdate_changes.xml index 3187fcfb8d55..5a0255647567 100644 --- a/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/noupdate_changes.xml +++ b/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/noupdate_changes.xml @@ -1,9 +1,9 @@ - + - + diff --git a/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/post-migration.py b/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/post-migration.py new file mode 100644 index 000000000000..7e926c95ebc2 --- /dev/null +++ b/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/post-migration.py @@ -0,0 +1,29 @@ +# Copyright 2023 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +def _unlink_non_applicable_questions(env): + """Set event_type_id = NULL on existing questions if the field `event_question` was + not marked in the event type. This way, we preserve possible existing answers, but + non desired questions are not done for the events of that type. + """ + openupgrade.logged_query( + env.cr, + """ + UPDATE event_question eq + SET event_type_id = NULL + FROM event_type et + WHERE et.id = eq.event_type_id + AND NOT et.use_questions + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data( + env.cr, "website_event_questions", "15.0.1.2/noupdate_changes.xml" + ) + _unlink_non_applicable_questions(env) diff --git a/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/pre-migration.py b/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/pre-migration.py new file mode 100644 index 000000000000..2e4fda861171 --- /dev/null +++ b/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/pre-migration.py @@ -0,0 +1,28 @@ +# Copyright 2023 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + +_xmlid_renames = [ + ( + "website_event_questions.event_question_all", + "website_event_questions.access_event_question", + ), + ( + "website_event_questions.event_question_event_user", + "website_event_questions.access_event_question_user", + ), + ( + "website_event_questions.event_question_answer_all", + "website_event_questions.access_event_question_answer", + ), + ( + "website_event_questions.event_question_answer_event_user", + "website_event_questions.access_event_question_answer_user", + ), +] + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_xmlids(env.cr, _xmlid_renames) diff --git a/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/upgrade_analysis_work.txt new file mode 100644 index 000000000000..47c4bbc00d3c --- /dev/null +++ b/openupgrade_scripts/scripts/website_event_questions/15.0.1.2/upgrade_analysis_work.txt @@ -0,0 +1,21 @@ +---Models in module 'website_event_questions'--- +---Fields in module 'website_event_questions'--- +website_event_questions / event.type / use_questions (boolean) : DEL +# DONE: post-migration: Set event_type_id = NULL on existing questions if the field was not marked in the event type. This way, we preserve possible existing answers. + +---XML records in module 'website_event_questions'--- +NEW ir.model.access: website_event_questions.access_event_question +NEW ir.model.access: website_event_questions.access_event_question_answer +NEW ir.model.access: website_event_questions.access_event_question_answer_user +NEW ir.model.access: website_event_questions.access_event_question_user +DEL ir.model.access: website_event_questions.event_question_all +DEL ir.model.access: website_event_questions.event_question_answer_all +DEL ir.model.access: website_event_questions.event_question_answer_event_user +DEL ir.model.access: website_event_questions.event_question_event_user +# DONE: pre-migration: Renamed XML-IDs + +DEL ir.model.access: website_event_questions.event_registration_answer_event_user +DEL ir.ui.view: website_event_questions.assets_tests +NEW ir.model.access: website_event_questions.access_event_registration_answer_registration +NEW ir.model.access: website_event_questions.access_event_question_answer_registration +# NOTHING TO DO: Extra noupdate=0 records \ No newline at end of file