Skip to content
Open
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
73 changes: 73 additions & 0 deletions openupgrade_scripts/scripts/website/18.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2026 Tecnativa - Pilar Vargas
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


def migrate_snippet_attribute(env, snippet_class, attribute, value):
openupgrade.logged_query(
env.cr,
rf"""
UPDATE ir_ui_view v
SET arch_db = data.arch_db
FROM (
SELECT view.id,
jsonb_object_agg(
lang,
regexp_replace(
arch,
$$<section(?=[^>]*class="[^"]*{snippet_class}[^"]*")(?![^>]*{attribute}=)([^>]*)>$$,
$$<section\1 {attribute}="{value}">$$,
'g'
)
) AS arch_db
FROM ir_ui_view view
CROSS JOIN LATERAL jsonb_each_text(view.arch_db) AS value(lang, arch)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the need of this join. You can do it with it I think.

WHERE view.website_id IS NOT NULL
AND view.arch_db::text LIKE '%{snippet_class}%'
GROUP BY view.id
) data
WHERE v.id = data.id
""",
)


def migrate_s_comparisons_snippets(env):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not refactoring this one?

openupgrade.logged_query(
env.cr,
r"""
UPDATE ir_ui_view v
SET arch_db = data.arch_db
FROM (
SELECT view.id,
jsonb_object_agg(
lang,
regexp_replace(
regexp_replace(
arch,
$$<section(?=[^>]*class="[^"]*s_comparisons[^"]*")(?![^>]*data-vxml=)([^>]*)>$$,
$$<section\1 data-vxml="001">$$,
'g'
),
$$<section(?=[^>]*class="[^"]*s_comparisons[^"]*")(?![^>]*data-vcss=)([^>]*)>$$,
$$<section\1 data-vcss="001">$$,
'g'
)
) AS arch_db
FROM ir_ui_view view
CROSS JOIN LATERAL jsonb_each_text(view.arch_db) AS value(lang, arch)
WHERE view.website_id IS NOT NULL
AND view.arch_db::text LIKE '%s_comparisons%'
GROUP BY view.id
) data
WHERE v.id = data.id
""",
)


@openupgrade.migrate()
def migrate(env, version):
migrate_snippet_attribute(env, "s_carousel_wrapper", "data-vcss", "001")
migrate_snippet_attribute(env, "s_three_columns", "data-vxml", "001")
migrate_snippet_attribute(env, "s_features_grid", "data-vcss", "001")
migrate_s_comparisons_snippets(env)
Loading