Skip to content

schema-check reports person_delete_audit missing even though function and trigger exist #31830

Description

@ForeignWelcome

I have searched the existing issues, both open and closed, to make sure this is not a duplicate report.

  • Yes

The bug

I am running Immich v3.2.2 from the TrueNAS Apps catalog and have been updating it through the TrueNAS catalog.

This schema drift warning has existed for several Immich updates, not only the latest one:

Migrations are up to date

Detected schema drift.
  - FunctionCreate: The function "person_delete_audit" is missing and needs to be created

immich-admin schema-check generates:

CREATE OR REPLACE FUNCTION person_delete_audit()
  RETURNS TRIGGER
  LANGUAGE PLPGSQL
  AS $$
    BEGIN
      INSERT INTO person_audit ("personGroupId", "ownerId")
      SELECT "personGroupId", "ownerId"
      FROM OLD;
      RETURN NULL;
    END
  $$;

I executed that exact SQL against the Immich PostgreSQL database and received:

CREATE FUNCTION
However, immich-admin schema-check still reports the function as missing, including after restarting Immich.

I verified that the function actually exists:

 schema |      function       | arguments
--------+---------------------+-----------
 public | person_delete_audit |

The function definition is:

CREATE OR REPLACE FUNCTION public.person_delete_audit()
 RETURNS trigger
 LANGUAGE plpgsql
AS $function$
    BEGIN
      INSERT INTO person_audit ("personGroupId", "ownerId")
      SELECT "personGroupId", "ownerId"
      FROM OLD;
      RETURN NULL;
    END
$function$

The trigger also exists and references the function:

person_delete_audit | CREATE TRIGGER person_delete_audit
AFTER DELETE ON public.person
REFERENCING OLD TABLE AS old
FOR EACH STATEMENT
WHEN ((pg_trigger_depth() <= 1))
EXECUTE FUNCTION person_delete_audit()

Both related migration override entries are present:

function_person_delete_audit
trigger_person_delete_audit

Immich is connected to the same database:

DB_PORT=5432
DB_DATABASE_NAME=immich
DB_HOSTNAME=pgvecto
DB_USERNAME=immich

So PostgreSQL appears to have the expected function and trigger, but schema-check continues to report FunctionCreate: person_delete_audit is missing.

Is this a schema-check detection issue, or is there another database object/metadata entry that should be checked?

The OS that Immich Server is running on

Truenas 25.10.7 - Goldeye

Version of Immich Server

v3.2.2

Version of Immich Mobile App

v3.2.1

Platform with the issue

  • Server
  • Web
  • Mobile

Device make and model

No response

Your docker-compose.yml content

immich from truenas cataloug

Your .env content

immich from truenas cataloug

Reproduction steps

1.after upgrading im not sure from which version to which version the error was there for a while
2.
3.
...

Relevant log output

### Relevant logs

Immich startup:


[Microservices:DatabaseRepository] Running migrations
[Microservices:DatabaseRepository] Finished running migrations
[Microservices:DatabaseService] Checking for schema drift
[Microservices:DatabaseService] Detected schema drift.
  - The function "person_delete_audit" is missing and needs to be created


The API worker reports the same thing:


[Api:DatabaseRepository] Running migrations
[Api:DatabaseRepository] Finished running migrations
[Api:DatabaseService] Checking for schema drift
[Api:DatabaseService] Detected schema drift.
  - The function "person_delete_audit" is missing and needs to be created


`immich-admin schema-check`:


Migrations are up to date

Detected schema drift.
  - FunctionCreate: The function "person_delete_audit" is missing and needs to be created


After creating the function successfully with the SQL generated by `schema-check`:


CREATE FUNCTION


Running `immich-admin schema-check` again still returns the same:


Migrations are up to date

Detected schema drift.
  - FunctionCreate: The function "person_delete_audit" is missing and needs to be created

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions