Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run db migrations prior to first startup #9177

Closed
1 of 3 tasks
nebulade opened this issue Apr 30, 2024 · 6 comments
Closed
1 of 3 tasks

Run db migrations prior to first startup #9177

nebulade opened this issue Apr 30, 2024 · 6 comments

Comments

@nebulade
Copy link
Contributor

The bug

Since 1.103.0 with https://github.com/immich-app/immich/pull/9118/files it seems one cannot run npm run typeorm:migrations:run anymore prior to the startup of the main app or at least it will use the hardcoded localhost for the postgres database.

For the Cloudron app package we need to configure some OpenID specific values in the database during app startup, which then naturally fails as tables don't exist yet on a fresh installation. Since we don't quite know once the main app startup has finished with the database migrations, we can't run those reliably now.

Is there any workaround for this or are we missing some other cli command to run migrations the same way the main app startup does but then exit after those have been run?

The OS that Immich Server is running on

Cloudron/Ubuntu

Version of Immich Server

v1.103.0

Version of Immich Mobile App

v1.103.0

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

does not apply

Your .env content

does not apply

Reproduction steps

Our startup script sets those env variables: https://git.cloudron.io/cloudron/immich-app/-/blob/main/env.sh?ref_type=heads
Then runs https://git.cloudron.io/cloudron/immich-app/-/blob/main/start.sh?ref_type=heads#L20

The OpenID related configs would be in the `start.sh` prior to running the services.

Relevant log output

No response

Additional information

No response

@bo0tzz
Copy link
Member

bo0tzz commented Apr 30, 2024

I think the hardcoded localhost is probably wrong since people might be developing against a database running on a different host. However for your use case, maybe it would be more appropriate to support some sort of trigger/hook that is called after server startup? That might also make it possible to use the API to configure things rather than needing to directly poke the database.

@jrasm91 thoughts?

@nebulade
Copy link
Contributor Author

I agree, poking the database directly is not a great idea, so far was just the only way to pre-setup this on behalf of the user. Does immich have an API which can be used on localhost without access tokens where we could just call the openid settings endpoint (and potentially other things)? Or would this be more the job for the immich-admin to have subcommands for that?

@jrasm91
Copy link
Contributor

jrasm91 commented Apr 30, 2024

I was not aware of a use case to manually run migrations through this command outside of development. We can make it possible to run against another host, but relying on it seems like a recipe for future issues. There is an API for setting and updating the configuration so maybe it is worth looking into a way to leverage the instead.

@nebulade
Copy link
Contributor Author

nebulade commented May 1, 2024

Ideally we don't want to run the database migration manually up front. This is really only needed as the OpenID auth settings are pre-provisioned for the user on Cloudron to have SSO across many apps installed on a server.

Maybe to circumvent the database migration/app bootstrapping issue, does Immich have a way to pre-provision certain settings, like picking up those values from env variables instead of the database if provided? Briefly looked through the code but didn't catch anything like that.

@bo0tzz
Copy link
Member

bo0tzz commented May 1, 2024

There is the config file, but I don't know whether that works for you as it fully locks the settings UI.

@nebulade
Copy link
Contributor Author

nebulade commented May 2, 2024

Actually I didn't realize an optional config file exists. This solves it nicely for our use-case. Thanks a lot for pointing me in the right direction, sorry for the distraction.

For others https://immich.app/docs/install/config-file is the docs link.

@nebulade nebulade closed this as completed May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants