diff --git a/script/database/migrate/process_backup_file.py b/script/database/migrate/process_backup_file.py new file mode 100644 index 0000000..b6a96e9 --- /dev/null +++ b/script/database/migrate/process_backup_file.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# © 2021-2025 TechnoLibre (http://www.technolibre.ca) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +import argparse +import sys +import zipfile + + +def process_zip( + path_backup_zip, path_output_zip, word_to_delete, file_to_modify +): + # Ouvrir le zip d'entrée en lecture + try: + with zipfile.ZipFile(path_backup_zip, "r") as zin, zipfile.ZipFile( + path_output_zip, "w" + ) as zout: + + # Parcourir tous les fichiers du zip + for item in zin.infolist(): + data = zin.read(item.filename) + if item.filename == file_to_modify: + + try: + # On suppose un fichier texte en UTF-8 + text = data.decode("utf-8") + except UnicodeDecodeError: + print( + f"Erreur : impossible de décoder {file_to_modify} en UTF-8", + file=sys.stderr, + ) + sys.exit(1) + + # Filtrer les lignes qui NE contiennent PAS le mot à supprimer + lines = text.splitlines( + keepends=True + ) # garder les fins de lignes + filtered_lines = [ + line for line in lines if word_to_delete not in line + ] + new_text = "".join(filtered_lines) + new_data = new_text.encode("utf-8") + + # Écrire la version modifiée dans le nouveau zip + zout.writestr(item, new_data) + else: + # Pour les autres fichiers, on recopie tel quel + zout.writestr(item, data) + + except FileNotFoundError: + print( + f"Erreur : fichier zip source introuvable : {path_backup_zip}", + file=sys.stderr, + ) + sys.exit(1) + + +def main(): + parser = argparse.ArgumentParser( + description="Modifier un fichier dans un zip en supprimant les lignes contenant un mot donné." + ) + parser.add_argument( + "--path_backup_zip", help="Chemin vers le zip original" + ) + parser.add_argument( + "--path_output_zip", help="Chemin vers le nouveau zip à créer" + ) + parser.add_argument( + "--word_to_delete", + help="Mot clé à supprimer (lignes contenant ce mot seront retirées)", + ) + parser.add_argument( + "--file_to_modify", + default="dump.sql", + help="Nom du fichier à modifier à l'intérieur du zip (chemin interne)", + ) + + args = parser.parse_args() + + process_zip( + args.path_backup_zip, + args.path_output_zip, + args.word_to_delete, + args.file_to_modify, + ) + + +if __name__ == "__main__": + main() diff --git a/script/odoo/migration/README.md b/script/odoo/migration/README.md index a5e395b..105e6e6 100644 --- a/script/odoo/migration/README.md +++ b/script/odoo/migration/README.md @@ -3,7 +3,7 @@ Run this script when doing database migration. Example : ```bash -cat ./script/migration/fix_migration_odoo140_to_odoo150.py | ./odoo15.0/odoo/odoo-bin shell -d DATABASE +source ./.venv.odoo15.0_python3.8.20/bin/activate && cat ./script/migration/fix_migration_odoo140_to_odoo150.py | ./odoo15.0/odoo/odoo-bin shell -d DATABASE ``` Check [uninstall_module_list_odoo140_to_odoo150.txt](uninstall_module_list_odoo140_to_odoo150.txt) diff --git a/script/postgresql/migration/fix_migration_postgresql_17_to_postgresql_18_module_mail_nov_2025.py b/script/postgresql/migration/fix_migration_postgresql_17_to_postgresql_18_module_mail_nov_2025.py new file mode 100644 index 0000000..10eec3e --- /dev/null +++ b/script/postgresql/migration/fix_migration_postgresql_17_to_postgresql_18_module_mail_nov_2025.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +# © 2021-2025 TechnoLibre (http://www.technolibre.ca) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +# This script fix the module mail when migrating postgresql 17 to postgresql 18 +print("Running a script in the Odoo shell!") + +# This fix +# odoo.sql_db: bad query: b'ALTER TABLE "discuss_channel_member" ADD FOREIGN KEY ("channel_id") REFERENCES "discuss_channel"("id") ON DELETE cascade' +# ERROR: insert or update on table "discuss_channel_member" violates foreign key constraint "discuss_channel_member_channel_id_fkey" +# DÉTAIL : Key (channel_id)=(3) is not present in table "discuss_channel". + +env.cr.execute(""" + ALTER TABLE discuss_channel + DROP CONSTRAINT discuss_channel_channel_type_not_null; +""") +env.cr.commit() + +#env.cr.execute("SELECT to_regclass('public.discuss_channel');") +#print("table:", env.cr.fetchone()) + +#print( +# "model discuss.channel:", +# env["ir.model"].search([("model", "=", "discuss.channel")]), +#) + +print("End fix migration with update mail postgresql 17 to postgresql 18.")