Immich: alternate method of migration

This commit is contained in:
vhsdream 2025-05-22 13:21:26 -04:00
parent 0163e04f1c
commit 58ad137936

View File

@ -184,15 +184,38 @@ function update_script() {
msg_ok "Stopped ${APP}"
if [[ "$(cat /opt/${APP}_version.txt)" < "1.133.0" ]]; then
msg_info "Upgrading to the VectorChord PostgreSQL extension"
NUMBER="$(
sed -n '2p' <(
sudo -u postgres psql -A -d immich <<EOF
SELECT atttypmod as dimsize
FROM pg_attribute f
JOIN pg_class c ON c.oid = f.attrelid
WHERE c.relkind = 'r'::char
AND f.attnum > 0
AND c.relname = 'smart_search'::text
AND f.attname = 'embedding'::text;
EOF
)
)"
$STD sudo -u postgres psql -d immich <<EOF
DROP INDEX IF EXISTS clip_index;
DROP INDEX IF EXISTS face_index;
ALTER TABLE smart_search ALTER COLUMN embedding SET DATA TYPE real[];
ALTER TABLE face_search ALTER COLUMN embedding SET DATA TYPE real[];
EOF
$STD apt-get update
$STD apt-get install postgresql-16-pgvector -y
curl -fsSL https://github.com/tensorchord/VectorChord/releases/download/0.3.0/postgresql-16-vchord_0.3.0-1_amd64.deb -o vchord.deb
$STD dpkg -i vchord.deb
rm vchord.deb
sed -i -e "s/'vectors.so'/'vchord.so, vectors.so'/" \
-e "/^search_path/s/, vectors//" /etc/postgresql/16/main/postgresql.conf
sed -i "s|vectors.so|vchord.so|" /etc/postgresql/16/main/postgresql.conf
systemctl restart postgresql.service
msg_ok "Upgrade in progress. When Immich restarts, watch the logs for 're-indexing' to complete"
$STD sudo -u postgres psql -d immich <<EOF
CREATE EXTENSION IF NOT EXISTS vchord CASCADE;
ALTER TABLE smart_search ALTER COLUMN embedding SET DATA TYPE vector($NUMBER);
ALTER TABLE face_search ALTER COLUMN embedding SET DATA TYPE vector(512);
EOF
msg_ok "Database upgrade complete"
fi
INSTALL_DIR="/opt/${APP}"
UPLOAD_DIR="${INSTALL_DIR}/upload"