Skip to content

nixos/doc/immich: init#344300

Closed
Scrumplex wants to merge 2 commits intoNixOS:masterfrom
Scrumplex:nixos/immich/migration-docs
Closed

nixos/doc/immich: init#344300
Scrumplex wants to merge 2 commits intoNixOS:masterfrom
Scrumplex:nixos/immich/migration-docs

Conversation

@Scrumplex
Copy link
Member

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Sep 24, 2024
Copy link
Contributor

@Titaniumtown Titaniumtown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM over all. I have a few nits, besides that. Thank you for the informative docs! I'm going to personally follow this guide now haha.

@Scrumplex Scrumplex force-pushed the nixos/immich/migration-docs branch from 619fc4f to facf01c Compare September 24, 2024 21:53
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Sep 25, 2024
@Scrumplex Scrumplex force-pushed the nixos/immich/migration-docs branch from facf01c to 7220cb6 Compare September 25, 2024 10:42
@Scrumplex Scrumplex marked this pull request as ready for review September 25, 2024 10:43
@h7x4 h7x4 added the 8.has: documentation This PR adds or changes documentation label Sep 25, 2024
@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Sep 26, 2024
@Scrumplex Scrumplex force-pushed the nixos/immich/migration-docs branch from 7220cb6 to 2f41434 Compare September 26, 2024 16:16
@github-actions github-actions bot removed the 8.has: documentation This PR adds or changes documentation label Sep 26, 2024
@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one person. label Sep 26, 2024
Copy link
Member

@getchoo getchoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly some punctuation nitpicks

@Atemu
Copy link
Member

Atemu commented Sep 27, 2024

@getchoo if you have this many tiny adjustments to recommend, it's usually easier for everyone involved to just PR them against the PR branch.

@getchoo
Copy link
Member

getchoo commented Sep 27, 2024

Scrumplex#1

Signed-off-by: Sefa Eyeoglu <[email protected]>
@Scrumplex Scrumplex force-pushed the nixos/immich/migration-docs branch 2 times, most recently from af33b50 to e7fae70 Compare September 28, 2024 08:39
@szethh
Copy link

szethh commented Sep 28, 2024

hi, I followed this guide and got stuck with some permission problems. inside my container based setup, the database user and owner of the tables was postgres. however in the nixos module, it's immich by default.

if you come across this issue, you can run this command on your db dump:
sed -i 's/OWNER TO postgres/OWNER TO immich/g' ./immich-final.sql

after that, it worked like a charm and all my images, users, faces etc popped up with no issues :)

thanks for writing up this guide!!

@Atemu
Copy link
Member

Atemu commented Sep 28, 2024

I think I ran into that when I did my manual migration before this guide's existence too. The guide should probably cover that.

@mhdask
Copy link

mhdask commented Oct 1, 2024

Hi, i followed this guide, and i ran into an issue with the database, it says that the migrations relations already exists:

Oct 01 23:36:38 immichcontainer server[557]: Starting microservices worker
Oct 01 23:36:41 immichcontainer server[557]: [Nest] 557  - 10/01/2024, 11:36:41 PM     LOG [Microservices:EventRepository] Initialized websocket server
Oct 01 23:36:41 immichcontainer server[557]: QueryFailedError: relation "migrations" already exists
Oct 01 23:36:41 immichcontainer server[557]:     at PostgresQueryRunner.query (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:219:19)
Oct 01 23:36:41 immichcontainer server[557]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Oct 01 23:36:41 immichcontainer server[557]:     at async PostgresQueryRunner.executeQueries (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/query-runner/BaseQueryRunner.js:425:13)
Oct 01 23:36:41 immichcontainer server[557]:     at async PostgresQueryRunner.createTable (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:425:9)
Oct 01 23:36:41 immichcontainer server[557]:     at async MigrationExecutor.createMigrationsTableIfNotExist (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/migration/MigrationExecutor.js:351:13)
Oct 01 23:36:41 immichcontainer server[557]:     at async MigrationExecutor.executePendingMigrations (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/migration/MigrationExecutor.js:129:9)
Oct 01 23:36:41 immichcontainer server[557]:     at async DataSource.runMigrations (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/data-source/DataSource.js:265:35)
Oct 01 23:36:41 immichcontainer server[557]:     at async DatabaseRepository.runMigrations (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/dist/repositories/database.repository.js:191:9)
Oct 01 23:36:41 immichcontainer server[557]:     at async /nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/dist/services/database.service.js:109:17
Oct 01 23:36:41 immichcontainer server[557]:     at async /nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/dist/repositories/database.repository.js:199:23 {
Oct 01 23:36:41 immichcontainer server[557]:   query: 'CREATE TABLE "migrations" ("id" SERIAL NOT NULL, "timestamp" bigint NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY ("id"))',
Oct 01 23:36:41 immichcontainer server[557]:   parameters: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   driverError: error: relation "migrations" already exists
Oct 01 23:36:41 immichcontainer server[557]:       at /nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/pg/lib/client.js:535:17
Oct 01 23:36:41 immichcontainer server[557]:       at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Oct 01 23:36:41 immichcontainer server[557]:       at async PostgresQueryRunner.query (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:184:25)
Oct 01 23:36:41 immichcontainer server[557]:       at async PostgresQueryRunner.executeQueries (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/query-runner/BaseQueryRunner.js:425:13)
Oct 01 23:36:41 immichcontainer server[557]:       at async PostgresQueryRunner.createTable (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:425:9)
Oct 01 23:36:41 immichcontainer server[557]:       at async MigrationExecutor.createMigrationsTableIfNotExist (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/migration/MigrationExecutor.js:351:13)
Oct 01 23:36:41 immichcontainer server[557]:       at async MigrationExecutor.executePendingMigrations (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/migration/MigrationExecutor.js:129:9)
Oct 01 23:36:41 immichcontainer server[557]:       at async DataSource.runMigrations (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/node_modules/typeorm/data-source/DataSource.js:265:35)
Oct 01 23:36:41 immichcontainer server[557]:       at async DatabaseRepository.runMigrations (/nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/dist/repositories/database.repository.js:191:9)
Oct 01 23:36:41 immichcontainer server[557]:       at async /nix/store/1v2r4l57p8qmsy8nk10gx558s6d2aj2p-immich-1.116.2/dist/services/database.service.js:109:17 {
Oct 01 23:36:41 immichcontainer server[557]:     length: 104,
Oct 01 23:36:41 immichcontainer server[557]:     severity: 'ERROR',
Oct 01 23:36:41 immichcontainer server[557]:     code: '42P07',
Oct 01 23:36:41 immichcontainer server[557]:     detail: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     hint: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     position: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     internalPosition: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     internalQuery: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     where: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     schema: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     table: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     column: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     dataType: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     constraint: undefined,
Oct 01 23:36:41 immichcontainer server[557]:     file: 'heap.c',
Oct 01 23:36:41 immichcontainer server[557]:     line: '1149',
Oct 01 23:36:41 immichcontainer server[557]:     routine: 'heap_create_with_catalog'
Oct 01 23:36:41 immichcontainer server[557]:   },
Oct 01 23:36:41 immichcontainer server[557]:   length: 104,
Oct 01 23:36:41 immichcontainer server[557]:   severity: 'ERROR',
Oct 01 23:36:41 immichcontainer server[557]:   code: '42P07',
Oct 01 23:36:41 immichcontainer server[557]:   detail: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   hint: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   position: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   internalPosition: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   internalQuery: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   where: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   schema: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   table: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   column: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   dataType: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   constraint: undefined,
Oct 01 23:36:41 immichcontainer server[557]:   file: 'heap.c',
Oct 01 23:36:41 immichcontainer server[557]:   line: '1149',
Oct 01 23:36:41 immichcontainer server[557]:   routine: 'heap_create_with_catalog'
Oct 01 23:36:41 immichcontainer server[557]: }
Oct 01 23:36:41 immichcontainer server[557]: microservices worker error: QueryFailedError: relation "migrations" already exists
Oct 01 23:36:41 immichcontainer server[557]: microservices worker exited with code 1
Oct 01 23:36:41 immichcontainer systemd[1]: immich-server.service: Main process exited, code=exited, status=1/FAILURE
Oct 01 23:36:41 immichcontainer systemd[1]: immich-server.service: Failed with result 'exit-code'.

@Atemu
Copy link
Member

Atemu commented Oct 1, 2024

@mhdask please share some info such as which version you're migrating from.

Also please just try again (wipe and everything), perhaps you just accidentally did something differently.

@mhdask
Copy link

mhdask commented Oct 1, 2024

@mhdask please share some info such as which version you're migrating from.

Also please just try again (wipe and everything), perhaps you just accidentally did something differently.

I am migrating from 1.115.0 to 1.116.2
I have tried making a new dump, and tried deleting everything within /var/lib/postgres, so there should not exist anything before importing the dump

If i do a SELECT * FROM migrations in the “old” database, a lot of lines come up

@Titaniumtown
Copy link
Contributor

@mhdask

While I dont know how many photos you have, I would really prefer not having to do this, as I have around 35k photos, 5k vidoes, which have been index, thumbnailed, machine learned, etc.. 😆

hahahah, very good point. My library is only a few thousand photos and I haven't done much with it yet.

@mhdask
Copy link

mhdask commented Oct 3, 2024

This is odd. TypeORM seems to check if the table exists before actually trying to create it. typeorm/typeorm@e7649d2/src/migration/MigrationExecutor.ts#L496
Could this be an issue with the search path?

@Scrumplex Is this something i can check?

It would be interesting to see if there are any unexpected differwnces between the original database dump from the container and your current state. Perhaps you could try to dump your current NixOS database and diff the two files. Obviously the media paths are going to be different, but perhaps something else is wrong too?

Im not sure which two dumps you want to compare, the one from the original (docker) database dump, and the new nixos service version?
I actually dont have difference in media paths, but I do run into the problem with the earthdistance thing.

UPDATE:
I finally figured it out - In my old setup, my database user was called postgres, so i had to run a command:
sed "s/Owner: postgres/Owner: immich/g" immich-fixed-search-path.sql to fix that issue.
After running that, and importing the database, I no longer got that same error

Copy link
Contributor

@akho akho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the guide. Commented on two points which caused issues. I think we need someone to run this beginning-to-end one more time.

@Scrumplex Scrumplex requested a review from akho October 21, 2024 13:24
@Scrumplex Scrumplex force-pushed the nixos/immich/migration-docs branch from e7fae70 to 2d4b7ce Compare October 21, 2024 13:24
Copy link
Contributor

@akho akho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both points seem fixed, thank you.

I’ve already done things in my new module-based install, so it’s not easy to do a run-through the new version as-is...

@akho
Copy link
Contributor

akho commented Oct 26, 2024

I've also had to re-create my external libraries, due to path mismatches with the container. Only noticed this now. Not sure what should have been done at db dump level.

This is really unfortunate, though — a lot of photos there…

@Atemu
Copy link
Member

Atemu commented Oct 26, 2024

Shouldn't you only have to adjust the import paths of the existing libraries? You can do that in the UI without touching the db.

@akho
Copy link
Contributor

akho commented Oct 26, 2024

Shouldn't you only have to adjust the import paths of the existing libraries? You can do that in the UI without touching the db.

Didn’t work for me.

@Scrumplex
Copy link
Member Author

Should we merge this as-is? I think we could also move this into the NixOS wiki alternatively and allow people to refine it there.

@getchoo
Copy link
Member

getchoo commented Nov 10, 2024

I think we could also move this into the NixOS wiki alternatively and allow people to refine it there.

I don't think that would be too bad of an idea. This is a pretty big section in the manual for something that's fairly specific

@Atemu
Copy link
Member

Atemu commented Nov 11, 2024

I feel like it's worth having in the official channel-specific "proper" documentation rather than the wiki.

I've been meaning to have another look, try it and then merge but I've been putting off migrating my Immich setup...

@karb94
Copy link
Contributor

karb94 commented Nov 30, 2024

I just completed my migration and I would like to share my experience following this guide.

  1. The second sed command needs the -E flag to allow the use of parenthesis without escaping them
  2. The second sed command did not replace multiple instances of 'upload/' in the same line. This is because it matches eagerly until the next forward slash ((.*)/) which in the case of multiple 'upload/' paths will match until the last one so the '/g' flag is useless. Instead, preventing the pattern from matching the tab character (used to separate the different fields) produced the desired result
sed -E "s#upload/([^\t]+)/#$TARGET_LOCATION/\1/#g" ./immich-fixed-search-path.sql > ./immich-final.sql
  1. I don't understand why this guide assumes that your postgres database username (DB_USERNAME) is 'immich' in the docker image. The default value upstream is 'postgres' so this guide won't work for 90% of the people (including myself and @mhdask). The sed command provided by @mhdask to fix database username issue wasn't converting all instances of 'postgres' into 'immich' so I ended up just using sed 's/postgres/immich/g' which seems to work fine.

diogotcorreia added a commit to diogotcorreia/dotfiles that referenced this pull request Dec 30, 2024
diogotcorreia added a commit to diogotcorreia/dotfiles that referenced this pull request Dec 30, 2024
diogotcorreia added a commit to diogotcorreia/dotfiles that referenced this pull request Dec 30, 2024
@diogotcorreia
Copy link
Member

Not sure if this is worth adding to this PR (or future wiki entry), but I was already using NixOS's PostgreSQL database, so I didn't have to move it around, just to change the paths in the data.
Instead of using sed, I simply used regexp_replace directly in PostgreSQL (my library is at /persist/immich):

START TRANSACTION;

UPDATE "asset_files" SET "path" = regexp_replace("path", '^upload/', '/persist/immich/');
UPDATE "assets" SET "originalPath" = regexp_replace("originalPath", '^upload/', '/persist/immich/');
UPDATE "assets" SET "encodedVideoPath" = regexp_replace("encodedVideoPath", '^upload/', '/persist/immich/');
UPDATE "assets" SET "sidecarPath" = regexp_replace("sidecarPath", '^upload/', '/persist/immich/');
UPDATE "move_history" SET "oldPath" = regexp_replace("oldPath", '^upload/', '/persist/immich/');
UPDATE "move_history" SET "newPath" = regexp_replace("newPath", '^upload/', '/persist/immich/');
UPDATE "person" SET "thumbnailPath" = regexp_replace("thumbnailPath", '^upload/', '/persist/immich/');
UPDATE "users" SET "profileImagePath" = regexp_replace("profileImagePath", '^upload/', '/persist/immich/');

COMMIT;

Either way, just wanted to leave this as a comment in case someone stumbles upon it.
Thank you so much for the migration guide, which helped a lot despite my setup being different!

Copy link
Member

@Atemu Atemu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guide did not work for my docker-compose based setup and needs to be changed accordingly.

Additionally I think @diogotcorreia's method of modifying the data via SQL feels a little cleaner but OTOH we need to modify the SQL dump anyways for the search path. (Postgres really ought to have a flag to just allow it.)
This is not something that needs to be implemented in this PR though.

Once that is fixed, this looks very good to me and we should have it.


These are assumptions and goals of this migration guide:

1. Your current installation's database name and username is `immich`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumption was not true for me and apparently multiple others too.

There needs to be a step that does:

sed -i 's/OWNER TO postgres/OWNER TO immich/g'

Otherwise you get confusing errors on startup such as "Must be owner of table exif" or that the table migrations already exists.


Example:
```console
# docker stop immich_server immich_machine_learning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

The way I did it which I think is slightly better is to docker compose down and then docker compose up database. This ensures only the DB is running which is what we want in this step.

named `immich_postgres`:

```console
# docker exec immich_postgres pg_dump --username immich immich > /var/backup/immich.sql
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The username needs to be postgres here.

Suggested change
# docker exec immich_postgres pg_dump --username immich immich > /var/backup/immich.sql
# docker exec immich_postgres pg_dump --username postgres immich > /var/backup/immich.sql

If this is not postgres in regular setups people actually have, perhaps this should be an env var too.

the following `sed` command:

```console
# sed "s#upload/(.*)/#$TARGET_LOCATION/\1/#g" ./immich-fixed-search-path.sql > ./immich-final.sql
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right and this didn't work for me at all.

@karb94's command worked for me:

Suggested change
# sed "s#upload/(.*)/#$TARGET_LOCATION/\1/#g" ./immich-fixed-search-path.sql > ./immich-final.sql
# sed -E "s#upload/([^\t]+)/#$TARGET_LOCATION/\1/#g" ./immich-fixed-search-path.sql > ./immich-final.sql

Copy link
Contributor

@melvyn2 melvyn2 Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, my installation was using absolute paths like /usr/src/app/upload/thumbs/... for some paths, but not all. I had to use sed -E "s#(^|\s)(/usr/src/app/)?upload/([^\t]+)/#\1/srv/large/photos/immich/\3/#g" ./immich-fixed-search-path.sql > ./immich-final.sql.

`immich-machine-learning.service` units.

```console
# systemctl stop immich-server.service immich-machine-learning.service
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It's slightly cleaner to stop these via the provided slice as that includes all of Immich's services in case there are any new ones in the future.

Suggested change
# systemctl stop immich-server.service immich-machine-learning.service
# systemctl stop system-immich.slice

Now that we prepared the database as well as the media location, we can finally start Immich and its other components:

```console
# systemctl start immich-server.service immich-machine-learning.service
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# systemctl start immich-server.service immich-machine-learning.service
# systemctl start system-immich.slice

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jun 25, 2025
@melvyn2
Copy link
Contributor

melvyn2 commented Aug 19, 2025

I had to adapt the path-fixing step slightly, because my database had a mix of absolute paths (/usr/src/app/upload) and relative paths. Also, I had to update the system metadata as well, otherwise I would see this error:

immich[192172]: [Nest] 192172  - 08/19/2025, 12:00:34 PM     LOG [Microservices:StorageService] Successfully verified system mount folder checks
immich[192172]: [Nest] 192172  - 08/19/2025, 12:00:34 PM     LOG [Microservices:StorageService] Media location changed (from=/usr/src/app/upload, to=/srv/large/photos/immich)
immich[192172]: Error: Detected an inconsistent media location. For more information, see https://immich.app/errors#inconsistent-media-location
immich[192172]:     at /nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/dist/services/storage.service.js:96:31
immich[192172]:     at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
immich[192172]:     at async /nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/dist/repositories/database.repository.js:379:27
immich[192172]:     at async /nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/node_modules/kysely/dist/cjs/kysely.js:535:20
immich[192172]:     at async DefaultConnectionProvider.provideConnection (/nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/node_modules/kysely/dist/cjs/driver/default-connection-provider.js>
immich[192172]:     at async /nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/dist/repositories/database.repository.js:376:13
immich[192172]: microservices worker error: Error: Detected an inconsistent media location. For more information, see https://immich.app/errors#inconsistent-media-location, stack: Error: Detected an >
immich[192172]:     at /nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/dist/services/storage.service.js:96:31
immich[192172]:     at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
immich[192172]:     at async /nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/dist/repositories/database.repository.js:379:27
immich[192172]:     at async /nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/node_modules/kysely/dist/cjs/kysely.js:535:20
immich[192172]:     at async DefaultConnectionProvider.provideConnection (/nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/node_modules/kysely/dist/cjs/driver/default-connection-provider.js>
immich[192172]:     at async /nix/store/phyl6h4rhs2qbpfcr4hvd8cn5snzppla-immich-1.138.0/dist/repositories/database.repository.js:376:13
immich[192172]: microservices worker exited with code 1
immich[192172]: Killing api process
systemd[1]: immich-server.service: Main process exited, code=exited, status=1/FAILURE

So this is the script that worked for me:

START TRANSACTION;

UPDATE "system_metadata" SET "value" = regexp_replace("value"::TEXT, '"(/usr/src/app/)?upload"', '"$TARGET_LOCATION/immich"')::JSONB WHERE "key" = 'MediaLocation';
UPDATE "asset_file" SET "path" = regexp_replace("path", '^(/usr/src/app/)?upload/', '$TARGET_LOCATION/immich/');
UPDATE "asset" SET "originalPath" = regexp_replace("originalPath", '^(/usr/src/app/)?upload/', '$TARGET_LOCATION/immich/'),
                   "encodedVideoPath" = regexp_replace("encodedVideoPath", '^(/usr/src/app/)?upload/', '$TARGET_LOCATION/immich/'),
                   "sidecarPath" = regexp_replace("sidecarPath", '^(/usr/src/app/)?upload/', '$TARGET_LOCATION/immich/');
UPDATE "move_history" SET "oldPath" = regexp_replace("oldPath", '^(/usr/src/app/)?upload/', '$TARGET_LOCATION/immich/'),
                          "newPath" = regexp_replace("newPath", '^(/usr/src/app/)?upload/', '$TARGET_LOCATION/immich/');
UPDATE "person" SET "thumbnailPath" = regexp_replace("thumbnailPath", '^(/usr/src/app/)?upload/', '$TARGET_LOCATION/immich/');
UPDATE "user" SET "profileImagePath" = regexp_replace("profileImagePath", '^(/usr/src/app/)?upload/', '$TARGET_LOCATION/immich/');

COMMIT;

I strongly recommend against including the sed path fixer in the final document. Postgres already provides a much more robust way to do what's needed without trying to parse sql dumps with regex.

@diogotcorreia
Copy link
Member

I believe the immich-admin change-media-location command (see 1.136.0 release notes) can be used for this instead of messing with the database now. We should definitely recommend it if it works for this use-case (haven't tested).

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 19, 2025
@Scrumplex
Copy link
Member Author

Maybe we should just have this in the NixOS Wiki instead.

@Scrumplex Scrumplex closed this Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.