[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.
This commit is contained in:
47
upgrade.sh
47
upgrade.sh
@@ -29,38 +29,31 @@ if [[ $# -lt 4 ]]; then
|
|||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
####################
|
readonly ORIGIN_VERSION="$1"
|
||||||
# GLOBAL VARIABLES #
|
readonly FINAL_VERSION="$2"
|
||||||
####################
|
readonly ORIGIN_DB_NAME="$3"
|
||||||
|
readonly ORIGIN_SERVICE_NAME="$4"
|
||||||
|
|
||||||
ORIGIN_VERSION="$1" # "12" for version 12.0
|
readonly COPY_DB_NAME="ou${ORIGIN_VERSION}"
|
||||||
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_DB_NAME="$3"
|
|
||||||
ORIGIN_SERVICE_NAME="$4"
|
|
||||||
|
|
||||||
# Get origin database name
|
|
||||||
COPY_DB_NAME="ou${ORIGIN_VERSION}"
|
|
||||||
# Define finale database name
|
|
||||||
export FINALE_DB_NAME="ou${FINAL_VERSION}"
|
export FINALE_DB_NAME="ou${FINAL_VERSION}"
|
||||||
# Define finale odoo service name
|
readonly FINALE_DB_NAME
|
||||||
FINALE_SERVICE_NAME="${FINALE_DB_NAME}"
|
readonly FINALE_SERVICE_NAME="${FINALE_DB_NAME}"
|
||||||
|
|
||||||
# Service postgres name (dynamically retrieved from running containers)
|
postgres_containers=$(docker ps --format '{{.Names}}' | grep postgres || true)
|
||||||
POSTGRES_CONTAINERS=$(docker ps --format '{{.Names}}' | grep postgres)
|
postgres_count=$(echo "$postgres_containers" | grep -c . || echo 0)
|
||||||
POSTGRES_COUNT=$(echo "$POSTGRES_CONTAINERS" | grep -c .)
|
|
||||||
|
|
||||||
if [[ "$POSTGRES_COUNT" -eq 0 ]]; then
|
if [[ "$postgres_count" -eq 0 ]]; then
|
||||||
log_error "No running PostgreSQL container found. Please start a PostgreSQL container and try again."
|
log_error "No running PostgreSQL container found. Please start a PostgreSQL container and try again."
|
||||||
exit 1
|
exit 1
|
||||||
elif [[ "$POSTGRES_COUNT" -gt 1 ]]; then
|
elif [[ "$postgres_count" -gt 1 ]]; then
|
||||||
log_error "Multiple PostgreSQL containers found:"
|
log_error "Multiple PostgreSQL containers found:"
|
||||||
echo "$POSTGRES_CONTAINERS" >&2
|
echo "$postgres_containers" >&2
|
||||||
log_error "Please ensure only one PostgreSQL container is running."
|
log_error "Please ensure only one PostgreSQL container is running."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export POSTGRES_SERVICE_NAME="$POSTGRES_CONTAINERS"
|
export POSTGRES_SERVICE_NAME="$postgres_containers"
|
||||||
|
readonly POSTGRES_SERVICE_NAME
|
||||||
|
|
||||||
log_step "INPUT PARAMETERS"
|
log_step "INPUT PARAMETERS"
|
||||||
log_info "Origin version .......... $ORIGIN_VERSION"
|
log_info "Origin version .......... $ORIGIN_VERSION"
|
||||||
@@ -78,19 +71,19 @@ log_info "Postgres service name .... $POSTGRES_SERVICE_NAME"
|
|||||||
|
|
||||||
log_step "CHECKS ALL NEEDED COMPONENTS ARE AVAILABLE"
|
log_step "CHECKS ALL NEEDED COMPONENTS ARE AVAILABLE"
|
||||||
|
|
||||||
DB_EXISTS=$(docker exec -it -u 70 "$POSTGRES_SERVICE_NAME" psql -tc "SELECT 1 FROM pg_database WHERE datname = '$ORIGIN_DB_NAME'" | tr -d '[:space:]')
|
db_exists=$(docker exec -it -u 70 "$POSTGRES_SERVICE_NAME" psql -tc "SELECT 1 FROM pg_database WHERE datname = '$ORIGIN_DB_NAME'" | tr -d '[:space:]')
|
||||||
if [[ "$DB_EXISTS" ]]; then
|
if [[ "$db_exists" ]]; then
|
||||||
log_info "Database '$ORIGIN_DB_NAME' found."
|
log_info "Database '$ORIGIN_DB_NAME' found."
|
||||||
else
|
else
|
||||||
log_error "Database '$ORIGIN_DB_NAME' not found in the local postgres service. Please add it and restart the upgrade process."
|
log_error "Database '$ORIGIN_DB_NAME' not found in the local postgres service. Please add it and restart the upgrade process."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
REPERTOIRE="${DATASTORE_PATH}/${ORIGIN_SERVICE_NAME}/${FILESTORE_SUBPATH}/${ORIGIN_DB_NAME}"
|
filestore_path="${DATASTORE_PATH}/${ORIGIN_SERVICE_NAME}/${FILESTORE_SUBPATH}/${ORIGIN_DB_NAME}"
|
||||||
if [[ -d "$REPERTOIRE" ]]; then
|
if [[ -d "$filestore_path" ]]; then
|
||||||
log_info "Filestore '$REPERTOIRE' found."
|
log_info "Filestore '$filestore_path' found."
|
||||||
else
|
else
|
||||||
log_error "Filestore '$REPERTOIRE' not found, please add it and restart the upgrade process."
|
log_error "Filestore '$filestore_path' not found, please add it and restart the upgrade process."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user