Skip to content
Merged
16 changes: 0 additions & 16 deletions fs_attachment/migrations/16.0.3.0.0/post-migration.py

This file was deleted.

21 changes: 21 additions & 0 deletions fs_attachment/upgrades/16.0.3.0.0/post-update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from openupgradelib import openupgrade

from odoo import _, exceptions


@openupgrade.migrate()
def migrate(env, version):
module = env["ir.module.module"].search(
[("name", "=", "fs_attachment_environment")]
)
if not module:
raise exceptions.UserError(
_(
"The 'fs_attachment_environment' module is not available. "
"It is required to preserve the server environment managed "
"fields of 'fs.storage'. Make it available on the "
"addons path before upgrading 'fs_attachment'."
)
)
if module.state == "uninstalled":
module.button_install()
1 change: 1 addition & 0 deletions fs_attachment_environment/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import post_init_hook, uninstall_hook
2 changes: 2 additions & 0 deletions fs_attachment_environment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
"depends": ["fs_storage_environment", "fs_attachment"],
"data": [],
"auto_install": True,
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
}
50 changes: 50 additions & 0 deletions fs_attachment_environment/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2026 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from psycopg2 import sql

from odoo import SUPERUSER_ID, api

from odoo.addons.server_environment.uninstall import restore_env_managed_columns

ENV_MANAGED_FIELDS = [
"optimizes_directory_path",
"autovacuum_gc",
"base_url",
"is_directory_path_in_url",
"use_x_sendfile_to_serve_internal_url",
"use_as_default_for_attachments",
"force_db_for_default_attachment_rules",
"use_filename_obfuscation",
"model_xmlids",
"field_xmlids",
]


def post_init_hook(cr, registry):
"""Preserve fallback values without violating the attachment rule constraint.

On a fresh install, Odoo initializes the new force database rules column on
existing storages with its non-empty default, even when the storage is not
the default attachment storage. The preservation helper writes fields back
through the ORM one at a time, so this temporary inconsistent state would
trigger the constraint. Normalize the stored fallback with SQL first.
"""
env = api.Environment(cr, SUPERUSER_ID, {})
env.cr.execute(
sql.SQL("UPDATE {} SET {} = NULL WHERE NOT COALESCE({}, FALSE)").format(
sql.Identifier(env["fs.storage"]._table),
sql.Identifier("force_db_for_default_attachment_rules"),
sql.Identifier("use_as_default_for_attachments"),
)
)
env["fs.storage"]._preserve_not_env_managed_data(ENV_MANAGED_FIELDS)


def uninstall_hook(env):
"""Restore database columns dropped by server.env.mixin."""
restore_env_managed_columns(
env,
"fs.storage",
ENV_MANAGED_FIELDS,
)
16 changes: 0 additions & 16 deletions fs_attachment_s3/migrations/16.0.3.0.0/post-migration.py

This file was deleted.

21 changes: 21 additions & 0 deletions fs_attachment_s3/upgrades/16.0.3.0.0/post-update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from openupgradelib import openupgrade

from odoo import _, exceptions


@openupgrade.migrate()
def migrate(env, version):
module = env["ir.module.module"].search(
[("name", "=", "fs_attachment_s3_environment")]
)
if not module:
raise exceptions.UserError(
_(
"The 'fs_attachment_s3_environment' module is not available. "
"It is required to preserve the server environment managed "
"fields of 'fs.storage'. Make it available on the "
"addons path before upgrading 'fs_attachment_s3'."
)
)
if module.state == "uninstalled":
module.button_install()
1 change: 1 addition & 0 deletions fs_attachment_s3_environment/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import post_init_hook, uninstall_hook
2 changes: 2 additions & 0 deletions fs_attachment_s3_environment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
"depends": ["fs_attachment_environment", "fs_attachment_s3"],
"data": [],
"auto_install": True,
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
}
25 changes: 25 additions & 0 deletions fs_attachment_s3_environment/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2026 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import SUPERUSER_ID, api

from odoo.addons.server_environment.uninstall import restore_env_managed_columns

ENV_MANAGED_FIELDS = [
"s3_uses_signed_url_for_x_sendfile",
"s3_signed_url_expiration",
]


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env["fs.storage"]._preserve_not_env_managed_data(ENV_MANAGED_FIELDS)


def uninstall_hook(env):
"""Restore database columns dropped by server.env.mixin."""
restore_env_managed_columns(
env,
"fs.storage",
ENV_MANAGED_FIELDS,
)
16 changes: 0 additions & 16 deletions fs_storage/migrations/16.0.2.0.0/post-migration.py

This file was deleted.

19 changes: 19 additions & 0 deletions fs_storage/upgrades/16.0.2.0.0/post-update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from openupgradelib import openupgrade

from odoo import _, exceptions


@openupgrade.migrate()
def migrate(env, version):
module = env["ir.module.module"].search([("name", "=", "fs_storage_environment")])
if not module:
raise exceptions.UserError(
_(
"The 'fs_storage_environment' module is not available. "
"It is required to preserve the server environment managed "
"fields of 'fs.storage'. Make it available on the "
"addons path before upgrading 'fs_storage'."
)
)
if module.state == "uninstalled":
module.button_install()
16 changes: 0 additions & 16 deletions fs_storage_backup/migrations/16.0.2.0.0/post-migration.py

This file was deleted.

21 changes: 21 additions & 0 deletions fs_storage_backup/upgrades/16.0.2.0.0/post-update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from openupgradelib import openupgrade

from odoo import _, exceptions


@openupgrade.migrate()
def migrate(env, version):
module = env["ir.module.module"].search(
[("name", "=", "fs_storage_backup_environment")]
)
if not module:
raise exceptions.UserError(
_(
"The 'fs_storage_backup_environment' module is not available. "
"It is required to preserve the server environment managed "
"fields of 'fs.storage'. Make it available on the "
"addons path before upgrading 'fs_storage_backup'."
)
)
if module.state == "uninstalled":
module.button_install()
1 change: 1 addition & 0 deletions fs_storage_backup_environment/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import post_init_hook, uninstall_hook
2 changes: 2 additions & 0 deletions fs_storage_backup_environment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
"depends": ["fs_storage_environment", "fs_storage_backup"],
"data": [],
"auto_install": True,
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
}
28 changes: 28 additions & 0 deletions fs_storage_backup_environment/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2026 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import SUPERUSER_ID, api

from odoo.addons.server_environment.uninstall import restore_env_managed_columns

ENV_MANAGED_FIELDS = [
"use_for_backup",
"backup_include_filestore",
"backup_filename_format",
"backup_keep_time",
"backup_dir",
]


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env["fs.storage"]._preserve_not_env_managed_data(ENV_MANAGED_FIELDS)


def uninstall_hook(env):
"""Restore database columns dropped by server.env.mixin."""
restore_env_managed_columns(
env,
"fs.storage",
ENV_MANAGED_FIELDS,
)
1 change: 1 addition & 0 deletions fs_storage_environment/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import post_init_hook, uninstall_hook
2 changes: 2 additions & 0 deletions fs_storage_environment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
"installable": True,
"depends": ["fs_storage", "server_environment"],
"data": [],
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
}
29 changes: 29 additions & 0 deletions fs_storage_environment/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2026 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import SUPERUSER_ID, api

from odoo.addons.server_environment.uninstall import restore_env_managed_columns

ENV_MANAGED_FIELDS = [
"protocol",
"options",
"directory_path",
"eval_options_from_env",
"check_connection_method",
]


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env["fs.storage"]._preserve_not_env_managed_data(ENV_MANAGED_FIELDS)


def uninstall_hook(env):
"""Restore database columns dropped by server.env.mixin."""
restore_env_managed_columns(
env,
"fs.storage",
ENV_MANAGED_FIELDS,
field_defaults={"protocol": "odoofs"},
)
Loading