From f7c968e1b87c942687a55e95466cf209d665a069 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 26 May 2025 09:22:46 +0200 Subject: [PATCH] Vchord --- postgres/rootfs/etc/cont-init.d/99-run.sh | 88 +++++++++++------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/postgres/rootfs/etc/cont-init.d/99-run.sh b/postgres/rootfs/etc/cont-init.d/99-run.sh index 54c04f6c2..fd796240a 100755 --- a/postgres/rootfs/etc/cont-init.d/99-run.sh +++ b/postgres/rootfs/etc/cont-init.d/99-run.sh @@ -9,7 +9,7 @@ set -e CONFIG_HOME="/config" PGDATA="${PGDATA:-/config/database}" PG_VERSION_FILE="$PGDATA/pg_major_version" -VECTORCHORD_VERSION_FILE="$PGDATA/vectorchord_version" +vchord_VERSION_FILE="$PGDATA/vchord_version" # Define current PostgreSQL major version PG_MAJOR_VERSION="${PG_MAJOR:-15}" @@ -46,11 +46,11 @@ cd /config || true bashio::log.info "Starting PostgreSQL..." if [ "$(bashio::info.arch)" = "armv7" ]; then - bashio::log.warning "ARMv7 detected: Starting without vectorchord.so" - docker-entrypoint.sh postgres & true + bashio::log.warning "ARMv7 detected: Starting without extensions" + /usr/local/bin/immich-docker-entrypoint.sh postgres & true exit 0 else - docker-entrypoint.sh postgres -c shared_preload_libraries=vectorchord.so -c search_path="public, vectorchord" & true + /usr/local/bin/immich-docker-entrypoint.sh postgres -c config_file=/etc/postgresql/postgresql.conf fi ############################### @@ -110,66 +110,66 @@ update_postgres() { } ##################################### -# Enable & Upgrade vectorchord # +# Enable & Upgrade vchord # ##################################### -# Function: Check if 'vectorchord' extension is enabled -check_vectorchord_extension() { - bashio::log.info "Checking if 'vectorchord' extension is enabled..." +# Function: Check if 'vchord' extension is enabled +check_vchord_extension() { + bashio::log.info "Checking if 'vchord' extension is enabled..." local result result=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" \ - -tAc "SELECT extname FROM pg_extension WHERE extname = 'vectorchord';") - if [[ "$result" == "vectorchord" ]]; then - bashio::log.info "'vectorchord' extension is enabled." + -tAc "SELECT extname FROM pg_extension WHERE extname = 'vchord';") + if [[ "$result" == "vchord" ]]; then + bashio::log.info "'vchord' extension is enabled." return 0 else - bashio::log.error "'vectorchord' extension is NOT enabled." + bashio::log.error "'vchord' extension is NOT enabled." return 1 fi } -# Function: Enable (or re-create) 'vectorchord' extension -enable_vectorchord_extension() { - bashio::log.info "Enabling 'vectorchord' extension..." - psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -c "DROP EXTENSION IF EXISTS vectorchord;" >/dev/null 2>&1 - psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -c "CREATE EXTENSION vectorchord;" >/dev/null 2>&1 - psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -c "ALTER EXTENSION vectorchord UPDATE;" >/dev/null 2>&1 +# Function: Enable (or re-create) 'vchord' extension +enable_vchord_extension() { + bashio::log.info "Enabling 'vchord' extension..." + psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -c "DROP EXTENSION IF EXISTS vchord;" >/dev/null 2>&1 + psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -c "CREATE EXTENSION vchord;" >/dev/null 2>&1 + psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -c "ALTER EXTENSION vchord UPDATE;" >/dev/null 2>&1 } -# Function: Store the current vectorchord version in a file -store_vectorchord_version() { +# Function: Store the current vchord version in a file +store_vchord_version() { local version version=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" \ - -tAc "SELECT extversion FROM pg_extension WHERE extname = 'vectorchord';") - echo "$version" > "$VECTORCHORD_VERSION_FILE" + -tAc "SELECT extversion FROM pg_extension WHERE extname = 'vchord';") + echo "$version" > "$vchord_VERSION_FILE" } -# Function: Detect previous and new vectorchord versions, and upgrade if needed -upgrade_vectorchord_extension() { +# Function: Detect previous and new vchord versions, and upgrade if needed +upgrade_vchord_extension() { local current_version desired_version - current_version=$(cat "$VECTORCHORD_VERSION_FILE" 2>/dev/null || echo "unknown") + current_version=$(cat "$vchord_VERSION_FILE" 2>/dev/null || echo "unknown") desired_version=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" \ - -tAc "SELECT extversion FROM pg_extension WHERE extname = 'vectorchord';") + -tAc "SELECT extversion FROM pg_extension WHERE extname = 'vchord';") if [[ "$current_version" != "$desired_version" ]]; then - bashio::log.warning "Upgrading 'vectorchord' extension from version $current_version → $desired_version..." - psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME@$DB_PORT" -c "ALTER EXTENSION vectorchord UPDATE;" >/dev/null 2>&1 + bashio::log.warning "Upgrading 'vchord' extension from version $current_version → $desired_version..." + psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME@$DB_PORT" -c "ALTER EXTENSION vchord UPDATE;" >/dev/null 2>&1 # Cleanup outdated indexes if needed (customize this line as needed for your DB schema) bashio::log.info "Cleaning up outdated vector indexes (if any)..." psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" \ -c "DROP INDEX IF EXISTS clip_index;" >/dev/null 2>&1 - # Store new vectorchord version - echo "$desired_version" > "$VECTORCHORD_VERSION_FILE" + # Store new vchord version + echo "$desired_version" > "$vchord_VERSION_FILE" else - bashio::log.info "'vectorchord' extension is already at the latest version ($desired_version)." + bashio::log.info "'vchord' extension is already at the latest version ($desired_version)." fi } -# Function: Troubleshoot vectorchord extension -troubleshoot_vectorchord_extension() { - bashio::log.error "Troubleshooting vectorchord installation..." +# Function: Troubleshoot vchord extension +troubleshoot_vchord_extension() { + bashio::log.error "Troubleshooting vchord installation..." if ! pg_isready -h "$DB_HOSTNAME" -p "$DB_PORT" -U "$DB_USERNAME" >/dev/null 2>&1; then bashio::log.error "PostgreSQL is not running or unreachable." @@ -178,9 +178,9 @@ troubleshoot_vectorchord_extension() { local ext_check ext_check=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" \ - -tAc "SELECT count(*) FROM pg_available_extensions WHERE name = 'vectorchord';") + -tAc "SELECT count(*) FROM pg_available_extensions WHERE name = 'vchord';") if [[ "$ext_check" -eq 0 ]]; then - bashio::log.error "'vectorchord' extension is missing. Ensure vectorchord is installed." + bashio::log.error "'vchord' extension is missing. Ensure vchord is installed." exit 1 fi } @@ -189,20 +189,20 @@ troubleshoot_vectorchord_extension() { # Main Extension Handling # ################################### -# Store previous vectorchord version +# Store previous vchord version update_postgres -if ! check_vectorchord_extension; then - enable_vectorchord_extension +if ! check_vchord_extension; then + enable_vchord_extension fi -# Store previous vectorchord version -store_vectorchord_version +# Store previous vchord version +store_vchord_version -# Upgrade vectorchord extension if needed -upgrade_vectorchord_extension +# Upgrade vchord extension if needed +upgrade_vchord_extension # Final verification -check_vectorchord_extension || troubleshoot_vectorchord_extension +check_vchord_extension || troubleshoot_vchord_extension bashio::log.info "All initialization steps completed successfully!" ) & true