Commit Graph

59 Commits

Author SHA1 Message Date
Stéphan Sainléger
febe877043 [FIX] correct undefined variable FINALE_DB_MODEL_NAME
Replace $FINALE_DB_MODEL_NAME with $FINALE_DB_NAME in the call to
prepare_db.sh.

FINALE_DB_MODEL_NAME was never defined anywhere in the codebase,
causing the script to fail immediately with 'set -u' (unbound variable
error). The intended variable is FINALE_DB_NAME which contains the
target database name (e.g., 'ou16').
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
f07a654c22 [IMP] factor out user confirmation prompts into reusable function
Add confirm_or_exit() function to lib/common.sh to eliminate duplicated
confirmation dialog code in prepare_db.sh.

Before: Two 10-line case statements with identical logic
After: Two single-line function calls

The function provides consistent behavior:
- Displays the question with Y/N options
- Returns 0 on Y/y (continue execution)
- Exits with error on any other input

This follows DRY principle and ensures all confirmation prompts
behave identically across the codebase.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
60d25124c4 [IMP] use rsync instead of cp for filestore copy
Replace mkdir + rm -rf + cp -a sequence with rsync --delete:

Before (3 commands):
  sudo mkdir -p "$dst_path"
  sudo rm -rf "$dst_path"
  sudo cp -a "$src_path" "$dst_path"

After (2 commands):
  sudo mkdir -p "$(dirname "$dst_path")"
  sudo rsync -a --delete "${src_path}/" "${dst_path}/"

Benefits:
- Incremental copy: only transfers changed files on re-run
- Atomic delete + copy: --delete removes extra files in destination
- Preserves all attributes like cp -a
- Faster for large filestores when re-running migration

Added rsync to required commands check.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
67c2d5a061 [IMP] combine SQL queries into single transaction with documentation
Merge three separate SQL queries into one for better performance:
- 1 database connection instead of 3
- Atomic execution of all cleanup operations

Added detailed SQL comments explaining each operation:
- DROP SEQUENCE: Why stale sequences prevent Odoo startup
- UPDATE ir_ui_view: Why website templates are reset except pages
- DELETE ir_attachment: Why compiled assets must be purged

Also changed DROP SEQUENCE to DROP SEQUENCE IF EXISTS to avoid
errors if sequences don't exist.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
e17db5d062 [IMP] simplify migration path construction with seq
Replace manual loop building version array with seq + readarray:

Before (4 lines):
  declare -a versions
  nb_migrations=$((FINAL_VERSION - ORIGIN_VERSION))
  for ((i = 0; i < nb_migrations; i++)); do
      versions[i]=$((ORIGIN_VERSION + 1 + i))
  done

After (1 line):
  readarray -t versions < <(seq $((ORIGIN_VERSION + 1)) "$FINAL_VERSION")

The seq command is purpose-built for generating number sequences,
making the intent clearer and the code more concise.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
89cc3be05e [IMP] simplify PostgreSQL container detection with readarray
Replace double grep pattern with readarray for cleaner container detection:
- Single grep call instead of two
- Native bash array instead of string manipulation
- Array length check instead of grep -c
- Proper formatting when listing multiple containers

The readarray approach is more idiomatic and avoids edge cases with
empty strings and newline handling.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
22d5b6af7e [IMP] remove redundant SQL query and grep for missing addons
The SQL query already filters on module_origin.state = 'installed',
so the second query to get installed addons and the grep intersection
were completely redundant.

Before: 2 SQL queries + grep + 3 temp files
After: 1 SQL query + variable

This simplifies the code and reduces database round-trips.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
00c12769bc [IMP] add external command verification at startup
Add check_required_commands() function to verify that all required
external tools are available before the script begins execution:
- docker: Container runtime
- compose: Docker compose wrapper (0k-scripts)
- sudo: Required for filestore operations

Benefits:
- Fails fast with a clear error message listing missing commands
- Prevents cryptic 'command not found' errors mid-execution
- Documents script dependencies explicitly
- Called immediately after argument validation in upgrade.sh
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
4bdedf3759 [IMP] apply naming conventions for variables
Apply consistent naming conventions throughout upgrade.sh:
- UPPERCASE + readonly for script-level constants (immutable values)
- lowercase for temporary/local variables within the script flow

Constants marked readonly:
- ORIGIN_VERSION, FINAL_VERSION, ORIGIN_DB_NAME, ORIGIN_SERVICE_NAME
- COPY_DB_NAME, FINALE_DB_NAME, FINALE_SERVICE_NAME
- POSTGRES_SERVICE_NAME

Local variables renamed to lowercase:
- postgres_containers, postgres_count (detection phase)
- db_exists, filestore_path (validation phase)

This convention makes it immediately clear which variables are
configuration constants vs runtime values, and prevents accidental
modification of critical values.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
1027428bfd [IMP] use mktemp and trap for temporary file cleanup
Replace hardcoded temporary file paths with mktemp -d for secure
temporary directory creation, and add a trap to automatically clean
up on script exit (success, failure, or interruption).

Benefits:
- Automatic cleanup even on Ctrl+C or script errors
- No leftover temporary files in the working directory
- Secure temporary directory creation (proper permissions)
- Files isolated in dedicated temp directory

Added '|| true' to grep command since it returns exit code 1 when
no matches are found, which would trigger set -e otherwise.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
01e23cc92c [IMP] use heredoc with variable expansion for SQL query
Convert the SQL_404_ADDONS_LIST query from a quoted string to a heredoc
without quotes (<<EOF instead of <<'EOF') to make variable expansion
explicit and consistent with other SQL blocks in the codebase.

Key difference between heredoc variants:
- <<'EOF': Literal content, no variable expansion (use for static SQL)
- <<EOF: Variables like ${FINALE_DB_NAME} are expanded (use when needed)

Also improved SQL formatting for better readability.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
d3f0998036 [IMP] add structured logging functions
Add logging functions to lib/common.sh for consistent output formatting:
- log_info(): Standard informational messages with [INFO] prefix
- log_warn(): Warning messages to stderr with [WARN] prefix
- log_error(): Error messages to stderr with [ERROR] prefix
- log_step(): Section headers with visual separators

Update upgrade.sh to use these functions throughout, replacing ad-hoc
echo statements. This provides:
- Consistent visual formatting across all scripts
- Clear distinction between info, warnings and errors
- Errors properly sent to stderr
- Easier log parsing and filtering

Also removed redundant '|| exit 1' statements since set -e handles
command failures automatically.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
914ae34f12 [IMP] centralize common functions in lib/common.sh
Extract shared utility functions into a dedicated library file:
- query_postgres_container: Execute SQL queries in postgres container
- copy_database: Copy database using pgm
- copy_filestore: Copy Odoo filestore directory
- exec_python_script_in_odoo_shell: Run Python scripts in Odoo shell

Benefits:
- Single source of truth for utility functions
- Easier maintenance and testing
- Consistent behavior across all scripts
- Reduced code duplication

Also introduces readonly constants DATASTORE_PATH and FILESTORE_SUBPATH
to avoid hardcoded paths scattered throughout the codebase.
2026-02-02 22:04:49 +01:00
Stéphan Sainléger
176fa0957c [FIX] correct undefined variable DB_CONTAINER_NAME
Replace $DB_CONTAINER_NAME with $POSTGRES_SERVICE_NAME which is the
correct variable exported from the parent script (upgrade.sh).

DB_CONTAINER_NAME was never defined, causing the script to fail
immediately with 'set -u' enabled (unbound variable error). The
intended variable is POSTGRES_SERVICE_NAME which contains the name
of the PostgreSQL container detected at runtime.
2026-02-02 22:04:41 +01:00
Stéphan Sainléger
8061d52d25 [FIX] correct return statement outside function
Replace 'return 1' with 'exit 1' in prepare_db.sh.

The 'return' statement is only valid inside functions. When used at
the script's top level, it behaves unpredictably - in some shells it
exits the script, in others it's an error. Using 'exit 1' explicitly
terminates the script with an error status, which is the intended
behavior when the PostgreSQL container is not running.
2026-02-02 22:04:20 +01:00
Stéphan Sainléger
3fe2e93d3d [IMP] use [[ instead of [ for conditionals
Replace single bracket [ ] with double bracket [[ ]] for all test
conditionals in the main scripts.

Benefits of [[ over [:
- No need to quote variables (though we still do for consistency)
- Supports regex matching with =~
- Supports pattern matching with == and !=
- && and || work inside [[ ]] without escaping
- More predictable behavior with empty strings
- Is a bash keyword, not an external command

Note: posbox scripts are left unchanged as they appear to be
third-party code imported into the repository.
2026-02-02 20:06:27 +01:00
Stéphan Sainléger
526b27fdec [IMP] fix variable quoting issues
Properly quote all variable expansions to prevent word splitting and
glob expansion issues:
- Quote $POSTGRES_SERVICE_NAME in docker exec command
- Quote $REPERTOIRE in directory test
- Remove unnecessary $ inside arithmetic expressions (($VAR -> VAR))

Unquoted variables can cause unexpected behavior when values contain
spaces or special characters. In arithmetic contexts, $ is unnecessary
and can mask errors with set -u.
2026-02-02 20:06:27 +01:00
Stéphan Sainléger
266842585b [IMP] add argument validation with usage message
Add proper argument validation at the start of upgrade.sh:
- Check that exactly 4 arguments are provided
- Display a helpful usage message with argument descriptions
- Include a concrete example command

This prevents cryptic errors when the script is called incorrectly
and provides clear guidance on expected parameters. With set -u enabled,
accessing unset positional parameters would cause an unclear error message.
2026-02-02 20:06:27 +01:00
Stéphan Sainléger
30909a3b28 [IMP] add strict mode (set -euo pipefail) to all scripts
Enable bash strict mode in all shell scripts to catch errors early:
- set -e: Exit immediately if a command exits with non-zero status
- set -u: Treat unset variables as an error
- set -o pipefail: Return value of a pipeline is the status of the last
  command to exit with non-zero status

This prevents silent failures and makes debugging easier by failing fast
when something goes wrong instead of continuing with potentially corrupted
state.
2026-02-02 20:06:27 +01:00
Stéphan Sainléger
4d7933cef0 [IMP] add final script to purge QWeb cache from compiled assets 2026-02-02 17:24:11 +01:00
Stéphan Sainléger
4a3d3b238f [IMP] add final script to reset all custom website templates 2026-02-02 17:23:24 +01:00
Stéphan Sainléger
59fc39620d [IMP] improves the way postgres container is detected 2026-01-16 14:19:51 +01:00
Stéphan Sainléger
7d001ff163 [IMP] adds pythons script to clean obsolete addons 2026-01-13 15:08:11 +01:00
Stéphan Sainléger
da59dffcfa [IMP] adds .gitignore 2026-01-13 12:50:16 +01:00
Stéphan Sainléger
d8b332762b [IMP] set debug log level on compose run commands 2026-01-13 12:44:35 +01:00
Stéphan Sainléger
023deeea5b [IMP] adds duplicated views cleaning at finalize db step 2026-01-13 12:39:17 +01:00
Stéphan Sainléger
743d1ce831 [IMP] adds check view python scripts at db preparation step 2026-01-13 12:38:47 +01:00
Stéphan Sainléger
469fb42e48 [IMP] add function to execute python scripts in Odoo shell 2026-01-13 12:37:38 +01:00
Stéphan Sainléger
f18d50cb94 [CLN] remove useless force_uninstall_addons file 2026-01-12 17:09:38 +01:00
Stéphan Sainléger
afeaa3d00f [IMP] fix the issue of account_analytic_plan migration in v17
Should be great to understand the origin of the problem one day...
2026-01-12 17:08:43 +01:00
Stéphan Sainléger
93fc10395f [IMP] add base in --load option of upgrade compose run command
due to account.invoice transformation in account.move
2026-01-12 17:00:03 +01:00
Stéphan Sainléger
458af6a795 [IMP] use odoo image rc/16.0-ELABORE-LIGHT instead of rc/16.0-MYC-INIT 2025-09-11 11:03:33 +02:00
Stéphan Sainléger
61733b04a3 [NEW] add migration scripts for Odoo 18.0 2025-09-11 11:03:29 +02:00
Stéphan Sainléger
385b9bc751 [NEW] add migration scripts for Odoo 17.0 2025-09-11 10:39:37 +02:00
Stéphan Sainléger
f432b4c75e [IMP] add commented command to launch global addons update at each step of the migration 2025-09-11 10:35:13 +02:00
Stéphan Sainléger
21028149be [IMP] update postgres version to 17.2.0 2025-09-11 10:33:39 +02:00
Stéphan Sainléger
972e6c7b26 [FIX] add su access for filestore manipulation 2025-09-11 10:31:52 +02:00
Boris Gallet
5feebec210 cln: img rc_15.0:latest and fix first iteration dir creation 2025-02-11 15:26:20 +01:00
Stéphan Sainléger
ad2b95d07d [IMP] better managment of model database in destination version 2025-02-11 14:58:27 +01:00
Stéphan Sainléger
7aeeccf88e imp: remove add-ons uninstall process
uninstall of add-ons is way too complicated due to dependencies.
the scripts now just list the add-ons that are installed in the
origin database, but not available in the final Odoo docker image.
2024-12-17 23:26:23 +01:00
Stéphan Sainléger
5dea543bb1 cln: remove Elabore migration specific sql scripts 2024-12-17 16:52:06 +01:00
Stéphan Sainléger
724e2b9831 imp: README.md improvement 2024-12-17 16:15:44 +01:00
Stéphan Sainléger
e19c05c812 imp: remove useless final model db name attribute 2024-12-17 15:57:22 +01:00
Stéphan Sainléger
564c0d75bc imp: remove useless .zip file attribute 2024-12-17 15:57:20 +01:00
Stéphan Sainléger
531c8db5be imp: README first version 2024-12-17 15:55:43 +01:00
Stéphan Sainléger
4afbcbf55b imp: several improvements on add-ons uninstall process
- only try to uninstall already installed add-ons
- display the final list of add-ons to remove (dependencies included)
- ask final confirmation
- remove useless temporary files
- clean code
2024-12-17 15:46:05 +01:00
Stéphan Sainléger
09a855258e imp: factorize database copy process 2024-12-17 15:46:05 +01:00
Stéphan Sainléger
c54cbe125b imp: factorize filestore copy process 2024-12-17 15:46:05 +01:00
Stéphan Sainléger
116d00091b imp: factorize query_postgres_container() in upgrade.sh 2024-12-17 15:46:05 +01:00
Stéphan Sainléger
53318a1a51 fix: typo on ir_module.state value 2024-12-17 15:46:05 +01:00