Compare commits

...

3 Commits

Author SHA1 Message Date
Vincent Van Rossem 783c3e331d [WIP] easy_my_coop: migration script 5 years ago
Vincent Van Rossem c659932ade [ADD] website_recaptcha_reloaded: pre-migration.py 5 years ago
Vincent Van Rossem fc19fb41aa [ADD] easy_my_coop: openupgrade.rename_xmlids() 5 years ago
  1. 42
      easy_my_coop/migrations/12.0.3.0.1/post-migration.py
  2. 82
      easy_my_coop/migrations/12.0.3.0.1/pre-migration.py
  3. 13
      website_recaptcha_reloaded/migrations/12.0.0.0.1/pre-migration.py

42
easy_my_coop/migrations/12.0.3.0.1/post-migration.py

@ -0,0 +1,42 @@
from openupgradelib import openupgrade
def update_records_module_category_cooperator_management(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE
res_groups_users_rel_module_category_cooperator_management
SET gid = (
SELECT id
FROM res_groups
WHERE name = 'User'
AND category_id = (
SELECT id
FROM ir_module_category
WHERE name = 'Cooperative Management'
)
);""",
)
openupgrade.logged_query(
env.cr,
"""
INSERT INTO res_groups_users_rel (gid, uid)
SELECT gid, uid FROM res_groups_users_rel_module_category_cooperator_management
ON CONFLICT DO NOTHING;""",
)
def drop_records_module_category_cooperator_management(env):
openupgrade.logged_query(
env.cr,
"""
DROP TABLE res_groups_users_rel_module_category_cooperator_management;""",
)
@openupgrade.migrate()
def migrate(env, version):
update_records_module_category_cooperator_management(env)
drop_records_module_category_cooperator_management(env)

82
easy_my_coop/migrations/12.0.3.0.1/pre-migration.py

@ -0,0 +1,82 @@
from openupgradelib import openupgrade
xmlid_renames = [
(
"easy_my_coop.group_energiris_user",
"easy_my_coop.group_easy_my_coop_user",
),
(
"easy_my_coop.group_energiris_manager",
"easy_my_coop.group_easy_my_coop_manager",
),
]
def copy_records_module_category_cooperator_management(env):
openupgrade.logged_query(
env.cr,
"""
CREATE TABLE res_groups_users_rel_module_category_cooperator_management AS
SELECT gid, uid
FROM res_groups_users_rel
WHERE gid = (
SELECT id
FROM res_groups
WHERE name = 'User'
AND category_id = (
SELECT id
FROM ir_module_category
WHERE name = 'EasyMy Coop'
)
)
ORDER BY gid,uid;""",
)
def delete_records_module_category_cooperator_management(env):
""""Since XML-ID module_category_cooperator_management is now flagged as noupdate="1",
we need to manually delete it as well as other records that are linked to it
"""
openupgrade.logged_query(
env.cr,
"""
DELETE
FROM res_groups_users_rel
WHERE gid = (
SELECT id
FROM res_groups
WHERE name = 'User'
AND category_id = (
SELECT id
FROM ir_module_category
WHERE name = 'EasyMy Coop'
)
);""",
)
openupgrade.logged_query(
env.cr,
"""
DELETE
FROM res_groups
WHERE name = 'User'
AND category_id = (
SELECT id
FROM ir_module_category
WHERE name = 'EasyMy Coop'
);""",
)
openupgrade.logged_query(
env.cr,
"""
DELETE
FROM ir_module_category
WHERE name = 'EasyMy Coop';""",
)
@openupgrade.migrate()
def migrate(env, version):
cr = env.cr
openupgrade.rename_xmlids(cr, xmlid_renames)
copy_records_module_category_cooperator_management(env)
delete_records_module_category_cooperator_management(env)

13
website_recaptcha_reloaded/migrations/12.0.0.0.1/pre-migration.py

@ -0,0 +1,13 @@
from openupgradelib import openupgrade
_field_renames = [
("website", "website", "recaptcha_site_key", "recaptcha_key_site"),
("website", "website", "recaptcha_private_key", "recaptcha_key_secret"),
("res.config.settings", "res_config_settings", "recaptcha_site_key", "recaptcha_key_site"),
("res.config.settings", "res_config_settings", "recaptcha_private_key", "recaptcha_key_secret"),
]
@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_fields(env, _field_renames)
Loading…
Cancel
Save