[NEW] add first version of 0k Odoo Upgrade scripts

This commit is contained in:
Stéphan Sainléger
2024-11-25 15:35:05 +01:00
parent 950c319040
commit 076a7bb3eb
19 changed files with 714 additions and 0 deletions

0
13.0/post_upgrade.sh Normal file
View File

45
13.0/pre_upgrade.sh Normal file
View File

@@ -0,0 +1,45 @@
#!/bin/bash
DB_CONTAINER_NAME="lokavaluto_postgres_1"
# Function to launch an SQL request to the postgres container
query_postgres_container(){
local query="$1"
if [ -z "$query" ]; then
return 0
fi
local result
if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d ou13 -t -A -c "$query" 2>&1); then
printf "Failed to execute SQL query: %s\n" "$query" >&2
printf "Error: %s\n" "$result" >&2
exit 1
fi
# Remove leading/trailing whitespace from result
result=$(echo "$result" | xargs)
echo "$result"
}
echo "Prepare migration to 13.0..."
# Copy database
docker exec -u 70 "$DB_CONTAINER_NAME" pgm cp -f ou12 ou13@ou13
# Execute SQL pre-migration commands
PRE_MIGRATE_SQL=$(cat <<'EOF'
/* Add analytic_policy column as openupgrade script is waiting for it whereas it doesn't existe since v12. */
ALTER TABLE public.account_account_type ADD analytic_policy varchar NULL;
/* The model in missing on some website_sale data */
UPDATE ir_model_data SET model = 'ir.ui.view' WHERE module = 'website_sale' AND name = 'recommended_products';
UPDATE ir_model_data SET model = 'ir.ui.view' WHERE module = 'website_sale' AND name = 'product_comment';
EOF
)
query_postgres_container "$PRE_MIGRATE_SQL"
# Copy filestores
rm -rf /srv/datastore/data/ou13/var/lib/odoo/filestore/ou13/* || exit 1
mkdir /srv/datastore/data/ou13/var/lib/odoo/filestore/ou13/* || exit 1
cp -a /srv/datastore/data/ou12/var/lib/odoo/filestore/ou12/* /srv/datastore/data/ou13/var/lib/odoo/filestore/ou13/ || exit 1
echo "Ready for migration to 13.0!"

3
13.0/upgrade.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
compose -f ../compose.yml run -p 8013:8069 ou13 --config=/opt/odoo/auto/odoo.conf --stop-after-init -u all --workers 0 --log-level=warn --max-cron-threads=0 --limit-time-real=10000 --database=ou13

0
14.0/post_upgrade.sh Normal file
View File

37
14.0/pre_upgrade.sh Normal file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
DB_CONTAINER_NAME="lokavaluto_postgres_1"
# Function to launch an SQL request to the postgres container
query_postgres_container(){
local query="$1"
if [ -z "$query" ]; then
return 0
fi
local result
if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d ou14 -t -A -c "$query" 2>&1); then
printf "Failed to execute SQL query: %s\n" "$query" >&2
printf "Error: %s\n" "$result" >&2
exit 1
fi
# Remove leading/trailing whitespace from result
result=$(echo "$result" | xargs)
echo "$result"
}
echo "Prepare migration to 14.0..."
# Copy database
docker exec -u 70 "$DB_CONTAINER_NAME" pgm cp -f ou13 ou14@ou14
# Execute SQL pre-migration commands
PRE_MIGRATE_SQL=""
query_postgres_container "$PRE_MIGRATE_SQL"
# Copy filestores
rm -rf /srv/datastore/data/ou14/var/lib/odoo/filestore/ou14/* || exit 1
mkdir /srv/datastore/data/ou14/var/lib/odoo/filestore/ou14/* || exit 1
cp -a /srv/datastore/data/ou13/var/lib/odoo/filestore/ou13/* /srv/datastore/data/ou14/var/lib/odoo/filestore/ou14/ || exit 1
echo "Ready for migration to 14.0!"

3
14.0/upgrade.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
compose -f ../compose.yml run -p 8014:8069 ou14 --config=/opt/odoo/auto/odoo.conf --stop-after-init -u all --workers 0 --log-level=warn --max-cron-threads=0 --limit-time-real=10000 --database=ou14 --load=web,openupgrade_framework

0
15.0/post_upgrade.sh Normal file
View File

43
15.0/pre_upgrade.sh Normal file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
DB_CONTAINER_NAME="lokavaluto_postgres_1"
# Function to launch an SQL request to the postgres container
query_postgres_container(){
local query="$1"
if [ -z "$query" ]; then
return 0
fi
local result
if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d ou15 -t -A -c "$query" 2>&1); then
printf "Failed to execute SQL query: %s\n" "$query" >&2
printf "Error: %s\n" "$result" >&2
exit 1
fi
# Remove leading/trailing whitespace from result
result=$(echo "$result" | xargs)
}
echo "Prepare migration to 15.0..."
# Copy database
docker exec -u 70 "$DB_CONTAINER_NAME" pgm cp -f ou14 ou15@ou15
# Execute SQL pre-migration commands
PRE_MIGRATE_SQL=$(cat <<'EOF'
/* Delete add-on 'account_usability' as its name has changed and another 'account_usability' add-on is created */
DELETE FROM ir_module_module WHERE name = 'account_usability';
DELETE FROM ir_model_data WHERE module = 'base' AND name = 'module_account_usability';
EOF
)
echo "SQL command = $PRE_MIGRATE_SQL"
query_postgres_container "$PRE_MIGRATE_SQL" >&1
# Copy filestores
rm -rf /srv/datastore/data/ou15/var/lib/odoo/filestore/ou15/* || exit 1
mkdir /srv/datastore/data/ou15/var/lib/odoo/filestore/ou15/* || exit 1
cp -a /srv/datastore/data/ou14/var/lib/odoo/filestore/ou14/* /srv/datastore/data/ou15/var/lib/odoo/filestore/ou15/ || exit 1
echo "Ready for migration to 15.0!"

3
15.0/upgrade.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
compose -f ../compose.yml run -p 8015:8069 ou15 --config=/opt/odoo/auto/odoo.conf --stop-after-init -u all --workers 0 --log-level=warn --max-cron-threads=0 --limit-time-real=10000 --database=ou15 --load=web,openupgrade_framework

0
16.0/post_upgrade.sh Normal file
View File

51
16.0/pre_upgrade.sh Normal file
View File

@@ -0,0 +1,51 @@
#!/bin/bash
DB_CONTAINER_NAME="lokavaluto_postgres_1"
# Function to launch an SQL request to the postgres container
query_postgres_container(){
local query="$1"
if [ -z "$query" ]; then
return 0
fi
local result
if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d ou16 -t -A -c "$query" 2>&1); then
printf "Failed to execute SQL query: %s\n" "$query" >&2
printf "Error: %s\n" "$result" >&2
exit 1
fi
# Remove leading/trailing whitespace from result
result=$(echo "$result" | xargs)
echo "$result"
}
echo "Prepare migration to 16.0..."
# Copy database
docker exec -u 70 "$DB_CONTAINER_NAME" pgm cp -f ou15 ou16@ou16
# Execute SQL pre-migration commands
PRE_MIGRATE_SQL=$(cat <<'EOF'
/* Remove duplicate entries in model utm.source */
DELETE FROM utm_source
WHERE id IN (
SELECT id
FROM (
SELECT id,
ROW_NUMBER() OVER (PARTITION BY name ORDER BY id) as row_num
FROM utm_source
) t
WHERE t.row_num > 1
);
EOF
)
echo "SQL command = $PRE_MIGRATE_SQL"
query_postgres_container "$PRE_MIGRATE_SQL"
# Copy filestores
rm -rf /srv/datastore/data/ou16/var/lib/odoo/filestore/ou16/* || exit 1
mkdir /srv/datastore/data/ou16/var/lib/odoo/filestore/ou16/* || exit 1
cp -a /srv/datastore/data/ou15/var/lib/odoo/filestore/ou15/* /srv/datastore/data/ou16/var/lib/odoo/filestore/ou16/ || exit 1
echo "Ready for migration to 16.0!"

3
16.0/upgrade.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
compose -f ../compose.yml run -p 8016:8069 ou16 --config=/opt/odoo/auto/odoo.conf --stop-after-init -u all --workers 0 --log-level=warn --max-cron-threads=0 --limit-time-real=10000 --database=ou16 --load=web,openupgrade_framework

8
404_addons Normal file
View File

@@ -0,0 +1,8 @@
account_balance_line
account_menu
account_statement_import
account_statement_import_file_reconciliation_widget
project_mail_chatter
project_timeline_task_dependency
web_drop_target
web_ir_actions_act_view_reload

32
combined_addons Normal file
View File

@@ -0,0 +1,32 @@
account_balance_line
account_menu
account_statement_import
account_statement_import_file_reconciliation_widget
project_mail_chatter
project_timeline_task_dependency
web_drop_target
web_ir_actions_act_view_reload
galicea_base
galicea_environment_checkup
mass_editing
mass_mailing_themes
muk_autovacuum
muk_fields_lobject
muk_fields_stream
muk_utils
muk_web_theme_mail
muk_web_utils
account_usability
kpi_dashboard
web_window_title
website_project_kanbanview
project_usability
project_tag
maintenance_server_monitoring_ping
maintenance_server_monitoring_ssh
maintenance_server_monitoring_memory
maintenance_server_monitoring_maintenance_equipment_status
maintenance_server_monitoring_disk
project_task_assignees_avatar
account_partner_reconcile
account_invoice_import_simple_pdf

78
compose.yml Normal file
View File

@@ -0,0 +1,78 @@
ou12:
charm: odoo-tecnativa
docker-compose:
image: docker.0k.io/mirror/odoo:rc_12.0-MYC-INIT-3.7
## Important to keep as a list: otherwise it'll overwrite charm's arguments.
command:
- "--log-level=debug"
- "--limit-time-cpu=1000000"
- "--limit-time-real=1000000"
options:
workers: 0
ou13:
charm: odoo-tecnativa
docker-compose:
image: docker.0k.io/mirror/odoo:rc_13.0-MYC-INIT-OU
## Important to keep as a list: otherwise it'll overwrite charm's arguments.
command:
- "--log-level=debug"
- "--limit-time-cpu=1000000"
- "--limit-time-real=1000000"
options:
workers: 0
ou14:
charm: odoo-tecnativa
docker-compose:
image: docker.0k.io/mirror/odoo:rc_14.0-MYC-INIT
## Important to keep as a list: otherwise it'll overwrite charm's arguments.
command:
- "--log-level=debug"
- "--limit-time-cpu=1000000"
- "--limit-time-real=1000000"
options:
workers: 0
ou15:
charm: odoo-tecnativa
docker-compose:
#image: docker.0k.io/mirror/odoo:rc_15.0-MYC-INIT
image: docker.0k.io/mirror/odoo/rc_15.0-myc-init-20241007-092844-0f8b8b
## Important to keep as a list: otherwise it'll overwrite charm's arguments.
command:
- "--log-level=debug"
- "--limit-time-cpu=1000000"
- "--limit-time-real=1000000"
options:
workers: 0
ou16:
charm: odoo-tecnativa
docker-compose:
image: docker.0k.io/mirror/odoo:rc_16.0-MYC-INIT
## Important to keep as a list: otherwise it'll overwrite charm's arguments.
command:
- "--log-level=debug"
- "--limit-time-cpu=1000000"
- "--limit-time-real=1000000"
options:
workers: 0
ou17:
charm: odoo-tecnativa
docker-compose:
image: docker.0k.io/mirror/odoo:rc_17.0-MYC-INIT
## Important to keep as a list: otherwise it'll overwrite charm's arguments.
command:
- "--log-level=debug"
- "--limit-time-cpu=1000000"
- "--limit-time-real=1000000"
options:
workers: 0
postgres:
docker-compose:
image: docker.0k.io/postgres:12.15.0-myc

38
finalize_db.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
DB_NAME="$1"
ODOO_SERVICE="$2"
DB_CONTAINER_NAME="lokavaluto_postgres_1"
# Function to launch an SQL request to the postgres container
query_postgres_container(){
local query="$1"
if [ "$query" ]; then
return 0
fi
local result
if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d "$DB_NAME" -t -A -c "$query" 2>&1); then
printf "Failed to execute SQL query: %s\n" "$query" >&2
printf "Error: %s\n" "$result" >&2
exit 1
fi
# Remove leading/trailing whitespace from result
result=$(echo "$result" | xargs)
echo "$result"
}
FINALE_SQL=$(cat <<'EOF'
/*Delte sequences that prevent Odoo to start*/
drop sequence base_registry_signaling;
drop sequence base_cache_signaling;
EOF
)
query_postgres_container "$FINALE_SQL"
# Give back the right to user to access to the tables
# docker exec -u 70 "$DB_CONTAINER_NAME" pgm chown "$FINALE_SERVICE_NAME" "$DB_NAME"
# Launch Odoo with database in finale version to run all updates
compose --debug run "$ODOO_SERVICE" -u all --stop-after-init --no-http

24
force_uninstall_addons Normal file
View File

@@ -0,0 +1,24 @@
galicea_base
galicea_environment_checkup
mass_editing
mass_mailing_themes
muk_autovacuum
muk_fields_lobject
muk_fields_stream
muk_utils
muk_web_theme_mail
muk_web_utils
account_usability
kpi_dashboard
web_window_title
website_project_kanbanview
project_usability
project_tag
maintenance_server_monitoring_ping
maintenance_server_monitoring_ssh
maintenance_server_monitoring_memory
maintenance_server_monitoring_maintenance_equipment_status
maintenance_server_monitoring_disk
project_task_assignees_avatar
account_partner_reconcile
account_invoice_import_simple_pdf

174
prepare_db.sh Executable file
View File

@@ -0,0 +1,174 @@
#!/bin/bash
# Global variables
ODOO_SERVICE="$1"
DB_NAME="$2"
DB_FINALE_MODEL="$3"
DB_FINALE_SERVICE="$4"
DB_CONTAINER_NAME="lokavaluto_postgres_1"
# Function to launch an SQL request to the postgres container
query_postgres_container(){
local query="$1"
if [ -z "$query" ]; then
return 0
fi
local result
if ! result=$(docker exec -u 70 $DB_CONTAINER_NAME psql -d $DB_NAME -t -A -c "$query" 2>&1); then
printf "Failed to execute SQL query: %s\n" "$query" >&2
printf "Error: %s\n" "$result" >&2
exit 1
fi
# Remove leading/trailing whitespace from result
result=$(echo "$result" | xargs)
echo "$result"
}
# Function to display the combined list of add-ons to uninstall
display_combined_list(){
cat 404_addons force_uninstall_addons > combined_addons
echo "UPGRADE: Add-ons to uninstall (forced and not found in final Odoo version):"
cat combined_addons
}
# Function to ask if the add-ons list to uninstall is OK
ask_confirmation() {
while true; do
echo "
Do you accept to uninstall all these add-ons? (Y/N/R)"
echo "Y - Yes, let's go on with the upgrade."
echo "N - No, stop the upgrade"
echo "R - I've edited the list, please Re-display it"
read -p "Your choice: " choice
case $choice in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
[Rr]* ) display_combined_list; continue;;
* ) echo "Please answer by Y, N or R.";;
esac
done
}
# Read names from file and create SQL commands
generate_sql_to_remove_commands() {
local name
local sql_commands=""
while IFS= read -r name; do
sql_commands+="UPDATE ir_module_module SET to_remove = TRUE WHERE name = '$name';"
done < combined_addons
echo "$sql_commands"
}
# Main execution
echo "UPGRADE: Start database preparation"
# Check POSTGRES container is running
if ! docker ps | grep -q "lokavaluto_postgres_1"; then
printf "Docker container %s is not running.\n" "lokavaluto_postgres_1" >&2
return 1
fi
EXT_EXISTS=$(query_postgres_container "SELECT 1 FROM pg_extension WHERE extname = 'dblink'")
if [ "$EXT_EXISTS" != "1" ]; then
query_postgres_container "CREATE EXTENSION dblink;"
fi
# Neutralize the database
SQL_NEUTRALIZE=$(cat <<'EOF'
/* Archive all the mail servers */
UPDATE fetchmail_server SET active = false;
UPDATE ir_mail_server SET active = false;
/* Archive all the cron */
ALTER TABLE ir_cron ADD COLUMN IF NOT EXISTS active_bkp BOOLEAN;
UPDATE ir_cron SET active_bkp = active;
UPDATE ir_cron SET active = False;
EOF
)
query_postgres_container "$SQL_NEUTRALIZE"
################################
## Uninstall unwished add-ons ##
################################
# Add columns to_remove and dependencies
SQL_INIT=$(cat <<'EOF'
ALTER TABLE ir_module_module ADD COLUMN IF NOT EXISTS to_remove BOOLEAN;
ALTER TABLE ir_module_module ADD COLUMN IF NOT EXISTS dependencies VARCHAR;
UPDATE ir_module_module SET state = 'installed' WHERE state = 'to_remove';
UPDATE ir_module_module SET to_remove = false;
UPDATE ir_module_module SET dependencies = '';
EOF
)
query_postgres_container "$SQL_INIT"
# List add-ons not available on the final Odoo version
SQL_404_ADDONS_LIST="
SELECT module_origin.name
FROM ir_module_module module_origin
LEFT JOIN (
SELECT *
FROM dblink('dbname=$DB_FINALE_MODEL','SELECT name, shortdesc, author FROM ir_module_module')
AS tb2(name text, shortdesc text, author text)
) AS module_dest ON module_dest.name = module_origin.name
WHERE (module_dest.name IS NULL) AND (module_origin.state = 'installed') AND (module_origin.author NOT IN ('Odoo S.A.', 'Lokavaluto', 'Elabore'))
ORDER BY module_origin.name
;
"
query_postgres_container "$SQL_404_ADDONS_LIST" > 404_addons
# Ask confirmation to uninstall the selected add-ons
display_combined_list
if ask_confirmation; then
echo "Upgrade goes on..."
else
echo "Upgrade stopped."
exit 1
fi
# Tag the selected add-ons as "to remove"
echo "TAG the add-ons to remove..."
SQL_TAG_TO_REMOVE=""
while IFS= read -r name; do
SQL_TAG_TO_REMOVE+="UPDATE ir_module_module SET to_remove = TRUE WHERE name = '$name' AND state = 'installed';"
done < combined_addons
query_postgres_container "$SQL_TAG_TO_REMOVE"
echo "Add-ons to be removed TAGGED."
# Identify the add-ons which depend on the add-on to uninstall
echo "Detect and tag add-ons dependencies..."
SQL_DEPENDENCIES="
UPDATE ir_module_module imm SET to_remove = true, dependencies = immd.name
FROM ir_module_module_dependency immd
WHERE immd.module_id = imm.id AND imm.state = 'installed' AND imm.to_remove = false
AND immd.name IN (
SELECT name FROM ir_module_module WHERE to_remove = True
);
"
updated=""
while [[ "$updated" != "UPDATE 0" ]]; do
updated=$(query_postgres_container "$SQL_DEPENDENCIES")
done;
echo "All dependencies to remove TAGGED"
# Change state of add-ons to remove
echo "Change state of all add-ons to remove..."
SQL_UPDATE_STATE="UPDATE ir_module_module SET state = 'to remove' WHERE to_remove = TRUE AND state = 'installed';"
query_postgres_container "$SQL_UPDATE_STATE"
echo "Add-ons to remove with state 'to_remove'"
# Launch Odooo container and launch the uninstall function
echo "Launch Odoo to uninstall add-ons..."
echo "print('START ADD-ONS UNINSTALL'); self.env['ir.module.module'].search([('state', '=', 'to remove')]).button_immediate_uninstall(); print('END ADD-ONS UNINSTALL')" | compose run $ODOO_SERVICE shell --database=$DB_NAME --no-http
echo "Add-ons uninstall successful."

172
upgrade.sh Executable file
View File

@@ -0,0 +1,172 @@
#!/bin/bash
####################
# GLOBAL VARIABLES #
####################
ORIGIN_VERSION="$1" # "12" for version 12.0
FINAL_VERSION="$2" # "16" for version 16.0
# Path to the database to migrate. Must be a .zip file with the following syntax: {DATABASE_NAME}.zip
ORIGIN_DATABASE_PATH="$3"
ORIGIN_SERVICE_NAME="$4"
FINALE_DB_MODEL_NAME="$5" #To check the add-ons available in the finale version
# Get origin database name
ORIGIN_DB_NAME=$(basename "$ORIGIN_DATABASE_PATH" .zip)
COPY_DB_NAME="ou${ORIGIN_VERSION}"
# Define finale database name
FINALE_DB_NAME="ou${FINAL_VERSION}"
# Define finale odoo service name
FINALE_SERVICE_NAME="${FINALE_DB_NAME}"
# Service postgres name
POSTGRES_SERVICE_NAME="lokavaluto_postgres_1"
#############################################
# DISPLAYS ALL INPUTS PARAMETERS
#############################################
echo "===== INPUT PARAMETERS ====="
echo "Origin version .......... $ORIGIN_VERSION"
echo "Final version ........... $FINAL_VERSION"
echo "Origin database path .... $ORIGIN_DATABASE_PATH"
echo "Origin service name ..... $ORIGIN_SERVICE_NAME"
echo "Finale DB model name .... $FINALE_DB_MODEL_NAME"
echo "
===== COMPUTED GLOBALE VARIABLES ====="
echo "Origin DB name ........... $ORIGIN_DB_NAME"
echo "Copy DB name ............. $COPY_DB_NAME"
echo "Finale DB name ........... $FINALE_DB_NAME"
echo "Finale service name ...... $FINALE_SERVICE_NAME"
echo "Postgres service name .... $POSTGRES_SERVICE_NAME"
##############################################
# CHECKS ALL NEEDED COMPONANTS ARE AVAILABLE #
##############################################
echo "
==== CHECKS ALL NEEDED COMPONANTS ARE AVAILABLE ===="
# Check origin database is in the local postgres
DB_EXISTS=$(docker exec -it -u 70 lokavaluto_postgres_1 psql -tc "SELECT 1 FROM pg_database WHERE datname = '$ORIGIN_DB_NAME'" | tr -d '[:space:]')
if [ "$DB_EXISTS" ]; then
echo "UPGRADE: Database '$ORIGIN_DB_NAME' found."
else
echo "ERROR: Database '$ORIGIN_DB_NAME' not found in the local postgress service. Please add it and restart the upgrade process."
exit 1
fi
# Check final version database model is in the local postgres
DB_EXISTS=$(docker exec -it -u 70 lokavaluto_postgres_1 psql -tc "SELECT 1 FROM pg_database WHERE datname = '$FINALE_DB_MODEL_NAME'" | tr -d '[:space:]')
if [ "$DB_EXISTS" ]; then
echo "UPGRADE: Database '$FINALE_DB_MODEL_NAME' found."
else
echo "ERROR: Database '$FINALE_DB_MODEL_NAME' not found in the local postgress service. Please add it and restart the upgrade process."
exit 1
fi
# Check that the origin filestore exist
REPERTOIRE="/srv/datastore/data/${ORIGIN_SERVICE_NAME}/var/lib/odoo/filestore/${ORIGIN_DB_NAME}"
if [ -d $REPERTOIRE ]; then
echo "UPGRADE: '$REPERTOIRE' filestore found."
else
echo "ERROR: '$REPERTOIRE' filestore not found, please add it and restart the upgrade process."
exit 1
fi
# Check POSTGRES container is running
if ! docker ps | grep -q "lokavaluto_postgres_1"; then
printf "Docker container %s is not running.\n" "lokavaluto_postgres_1" >&2
return 1
else
echo "UPGRADE: container lokavaluto_postgres_1 running."
fi
############################
# COPY ORIGINAL COMPONANTS #
############################
echo "
==== COPY ORIGINAL COMPONANTS ===="
echo "UPGRADE: Start copy"
# Copy database
docker exec -u 70 lokavaluto_postgres_1 pgm cp -f "$ORIGIN_DB_NAME" "${COPY_DB_NAME}@${COPY_DB_NAME}" || exit 1
echo "UPGRADE: original database copied in ${COPY_DB_NAME}@${COPY_DB_NAME}."
# Copy filestore
rm -rf /srv/datastore/data/${COPY_DB_NAME}/var/lib/odoo/filestore/${COPY_DB_NAME} || exit 1
mkdir /srv/datastore/data/${COPY_DB_NAME}/var/lib/odoo/filestore/${COPY_DB_NAME} || exit 1
cp -a /srv/datastore/data/$ORIGIN_SERVICE_NAME/var/lib/odoo/filestore/$ORIGIN_DB_NAME/* /srv/datastore/data/$COPY_DB_NAME/var/lib/odoo/filestore/$COPY_DB_NAME/. || exit 1
echo "UPGRADE: original filestore copied."
#####################
# PATH OF MIGRATION #
####################
echo "
==== PATH OF MIGRATION ===="
# List all the versions to migrate through
declare -a versions
nb_migrations=$(($FINAL_VERSION - $ORIGIN_VERSION))
# Build the migration path
for ((i = 0; i<$nb_migrations; i++))
do
versions[$i]=$(($ORIGIN_VERSION + 1 + i))
done
echo "UPGRADE: Migration path is ${versions[@]}"
########################
# DATABASE PREPARATION #
########################
echo "
==== DATABASE PREPARATION ===="
source prepare_db.sh "$COPY_DB_NAME" "$COPY_DB_NAME" "$FINALE_DB_MODEL_NAME" "$FINALE_SERVICE_NAME"
###################
# UPGRADE PROCESS #
###################
for version in "${versions[@]}"
do
echo "START UPGRADE TO ${version}.0"
start_version=$((version-1))
end_version="$version"
### Go to the repository holding the upgrate scripts
cd "${end_version}.0"
### Execute pre_upgrade scripts
source ./pre_upgrade.sh
### Start upgrade
source ./upgrade.sh
### Execute post-upgrade scripts
source ./post_upgrade.sh
### Return to parent repository for the following steps
cd ..
echo "END UPGRADE TO ${version}.0"
done
## END UPGRADE LOOP
##########################
# POST-UPGRADE PROCESSES #
##########################
source finalize_db.sh "$FINALE_DB_NAME" "$FINALE_SERVICE_NAME"
echo "UPGRADE PROCESS ENDED WITH SUCCESS"