immich-app / immich

High performance self-hosted photo and video management solution.
https://immich.app
GNU Affero General Public License v3.0
51.43k stars 2.72k forks source link

Migration NullifyFutureBirthDatesAndAddCheckConstraint1702938928766 failed after update (but a restart "fixed" it) #6936

Closed wutr closed 9 months ago

wutr commented 9 months ago

The bug

This is an informative report, since it seems to have been sorted after restarting Immich, but it may still be relevant to someone encountering the same issue, or maybe it will help prevent a bigger problem in the future.

When updating from Immich v1.91.4 to v1.94.1 the following error occurred in the immich_server container:

Details

``` podman logs immich_server Migration "NullifyFutureBirthDatesAndAddCheckConstraint1702938928766" failed, error: constraint "CHK_b0f82b0ed662bfc24fbb58bb45" for relation "person" already exists /usr/src/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:219 throw new QueryFailedError_1.QueryFailedError(query, parameters, err); ^ QueryFailedError: constraint "CHK_b0f82b0ed662bfc24fbb58bb45" for relation "person" already exists at PostgresQueryRunner.query (/usr/src/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:219:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async NullifyFutureBirthDatesAndAddCheckConstraint1702938928766.up (/usr/src/app/dist/infra/migrations/1702938928766-NullifyFutureBirthDatesAndAddCheckConstraint.js:10:9) at async MigrationExecutor.executePendingMigrations (/usr/src/app/node_modules/typeorm/migration/MigrationExecutor.js:225:17) at async DataSource.runMigrations (/usr/src/app/node_modules/typeorm/data-source/DataSource.js:263:35) at async DatabaseRepository.runMigrations (/usr/src/app/dist/infra/repositories/database.repository.js:42:9) at async DatabaseService.init (/usr/src/app/dist/domain/database/database.service.js:33:9) at async AppService.init (/usr/src/app/dist/immich/app.service.js:56:9) at async AppModule.onModuleInit (/usr/src/app/dist/immich/app.module.js:32:9) at async callModuleInitHook (/usr/src/app/node_modules/@nestjs/core/hooks/on-module-init.hook.js:51:9) { query: 'ALTER TABLE "person" ADD CONSTRAINT "CHK_b0f82b0ed662bfc24fbb58bb45" CHECK ("birthDate" <= CURRENT_DATE)', parameters: undefined, driverError: error: constraint "CHK_b0f82b0ed662bfc24fbb58bb45" for relation "person" already exists at /usr/src/app/node_modules/pg/lib/client.js:526:17 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async PostgresQueryRunner.query (/usr/src/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:184:25) at async NullifyFutureBirthDatesAndAddCheckConstraint1702938928766.up (/usr/src/app/dist/infra/migrations/1702938928766-NullifyFutureBirthDatesAndAddCheckConstraint.js:10:9) at async MigrationExecutor.executePendingMigrations (/usr/src/app/node_modules/typeorm/migration/MigrationExecutor.js:225:17) at async DataSource.runMigrations (/usr/src/app/node_modules/typeorm/data-source/DataSource.js:263:35) at async DatabaseRepository.runMigrations (/usr/src/app/dist/infra/repositories/database.repository.js:42:9) at async DatabaseService.init (/usr/src/app/dist/domain/database/database.service.js:33:9) at async AppService.init (/usr/src/app/dist/immich/app.service.js:56:9) at async AppModule.onModuleInit (/usr/src/app/dist/immich/app.module.js:32:9) { length: 151, severity: 'ERROR', code: '42710', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'heap.c', line: '2899', routine: 'MergeWithExistingConstraint' }, length: 151, severity: 'ERROR', code: '42710', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'heap.c', line: '2899', routine: 'MergeWithExistingConstraint' } Node.js v20.11.0 ```

This seems linked to the following change: https://github.com/immich-app/immich/pull/5803

I run this in rootless podman (and have done since v1.50.0 of March 2023), in case it's relevant.

The OS that Immich Server is running on

Ubuntu 22.04

Version of Immich Server

1.94.1

Version of Immich Mobile App

1.93.1

Platform with the issue

Your docker-compose.yml content

# 'name' element introduced in immich 1.86  won't work with docker-compose version <v2.0, 
#  but docker-compose v2.0+ won't work with podman v3.4 (requires v4.0+). Maybe try podman-compose
#
#  Always compare with: https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
#
#version: "3.8"
#name: immich

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    command: ["start.sh", "immich"]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    restart: always

  immich-microservices:
    container_name: immich_microservices
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/hardware-transcoding
    #   file: hwaccel.transcoding.yml
    #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    command: ["start.sh", "microservices"]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    depends_on:
      - redis
      - database
    restart: always

  immich-machine-learning:
    container_name: immich_machine_learning
    # For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.
    # Example tag: ${IMMICH_VERSION:-release}-cuda
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
    # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration
    #   file: hwaccel.ml.yml
    #   service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable
    volumes:
      - /opt/appdata/immich/model-cache:/cache
    env_file:
      - .env
    restart: always

  redis:
    container_name: immich_redis
    image: docker.io/redis:6.2-alpine
    restart: always

  database:
    container_name: immich_postgres
    image: docker.io/tensorchord/pgvecto-rs:pg14-v0.1.11 
    env_file:
      - .env
    environment:
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_USER=${DB_USERNAME}
      - POSTGRES_DB=${DB_DATABASE_NAME}
    volumes:
      - /opt/appdata/immich/pgdata:/var/lib/postgresql/data
    restart: always

Your .env content

IMMICH_VERSION="v1.94.1"

###################################################################################
# Database
###################################################################################

DB_HOSTNAME=immich_postgres
DB_USERNAME=postgres
DB_PASSWORD=
DB_DATABASE_NAME=immich

# Optional Database settings:
# DB_PORT=5432

###################################################################################
# Redis
###################################################################################

REDIS_HOSTNAME=immich_redis

# Optional Redis settings:

# Note: these parameters are not automatically passed to the Redis Container
# to do so, please edit the docker-compose.yml file as well. Redis is not configured
# via environment variables, only redis.conf or the command line

# REDIS_PORT=6379
# REDIS_DBINDEX=0
# REDIS_PASSWORD=
# REDIS_SOCKET=

###################################################################################
# Upload File Location
#
# This is the location where uploaded files are stored.
###################################################################################

UPLOAD_LOCATION=/datapool/immich

###################################################################################
# Typesense REMOVED IN 1.91.0 onwards
###################################################################################
# TYPESENSE_API_KEY=
# TYPESENSE_ENABLED=false

###################################################################################
# Reverse Geocoding
#
# Reverse geocoding is done locally which has a small impact on memory usage
# This memory usage can be altered by changing the REVERSE_GEOCODING_PRECISION variable
# This ranges from 0-3 with 3 being the most precise
# 3 - Cities > 500 population: ~200MB RAM
# 2 - Cities > 1000 population: ~150MB RAM
# 1 - Cities > 5000 population: ~80MB RAM
# 0 - Cities > 15000 population: ~40MB RAM
####################################################################################

# DISABLE_REVERSE_GEOCODING=false
# REVERSE_GEOCODING_PRECISION=3

####################################################################################
# WEB - Optional
#
# Custom message on the login page, should be written in HTML form.
# For example:
# PUBLIC_LOGIN_PAGE_MESSAGE="This is a demo instance of Immich.<br><br>Email: <i>demo@demo.de</i><br>Password: <i>demo</i>"
####################################################################################

PUBLIC_LOGIN_PAGE_MESSAGE=

####################################################################################
# Alternative Service Addresses - Optional
#
# This is an advanced feature for users who may be running their immich services on different hosts.
# It will not change which address or port that services bind to within their containers, but it will change where other services look for their peers.
# Note: immich-microservices is bound to 3002, but no references are made
####################################################################################

# --- NO LONGER REQUIRED BY DEFAULT SINCE v1.82.0 (can still be overwritten) ---   #
#IMMICH_WEB_URL=http://immich-web:3000
#IMMICH_SERVER_URL=http://immich-server:3001
#IMMICH_MACHINE_LEARNING_URL=http://immich-machine-learning:3003

####################################################################################
# Alternative API's External Address - Optional
#
# This is an advanced feature used to control the public server endpoint returned to clients during Well-known discovery.
# You should only use this if you want mobile apps to access the immich API over a custom URL. Do not include trailing slash.
# NOTE: At this time, the web app will not be affected by this setting and will continue to use the relative path: /api
# Examples: http://localhost:3001, http://immich-api.example.com, etc
####################################################################################

#IMMICH_API_URL_EXTERNAL=http://localhost:3001

Reproduction steps

1. Stop the Immich containers (docker-compose down)
2. Update Immich from v1.91.4 to v1.94.1
3. Start the Immich containers (docker-compose up -d)
4. The error occurred
5. Stop the Immich containers (docker-compose down)
6. Start the Immich containers (docker-compose up -d)

I don't know if this will reoccur if I were to downgrade back to v1.91.4 and upgrade again.
...

Additional information

No response

bo0tzz commented 9 months ago

https://immich.app/docs/FAQ#why-does-immich-log-migration-errors-on-startup