Skip to content

Added a prefix (postgresql schema) from env variable into runtime.exs…#526

Open
sachabertschibfs wants to merge 5 commits intopentacent:mainfrom
sachabertschibfs:feature/set-postgresql-prefix-for-oban
Open

Added a prefix (postgresql schema) from env variable into runtime.exs…#526
sachabertschibfs wants to merge 5 commits intopentacent:mainfrom
sachabertschibfs:feature/set-postgresql-prefix-for-oban

Conversation

@sachabertschibfs
Copy link
Copy Markdown
Contributor

… and also directly into the Oban migration.

@wmnnd
Copy link
Copy Markdown
Contributor

wmnnd commented Apr 20, 2026

Hey there, thanks for the PR! There are actually multiple Oban migrations (try looking for Oban.Migrations.up). Do they work without the prefix?

@sachabertschibfs
Copy link
Copy Markdown
Contributor Author

Oops, I missed those, I'll add them.

@sachabertschibfs
Copy link
Copy Markdown
Contributor Author

I found a few more prefix to deal with. It should now migrate without problem and run.
It would be best if you test it yourself of course ^^

@sachabertschibfs
Copy link
Copy Markdown
Contributor Author

Hello @wmnnd ,
Could you review the pr?
I believe the migrations and the application run fine with a different schema than public now.
Best Regards,
Sacha Bertschi

@wmnnd
Copy link
Copy Markdown
Contributor

wmnnd commented Apr 29, 2026

Hey there, the current implementation doesn't work because you've moved the schema settings to config.exs. However, config.exs is run only at compile-time so it won't be possible to change this at runtime (i.e. when starting as a container).

@wmnnd
Copy link
Copy Markdown
Contributor

wmnnd commented Apr 29, 2026

I think the following code in runtime.exs should be sufficient (config merges keys automatically):

db_schema = System.get_env("DB_SCHEMA")
if db_schema not in [nil, ""] do
  config :keila, Keila.Repo,
    migration_default_prefix: db_schema,
    parameters: [search_path: db_schema]

  config :keila, Oban, prefix: db_schema
end

I suggest it you put it underneath the existing # Database try/catch block and add a #Database prefix comment,

Could you give that a try?

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

Successfully merging this pull request may close these issues.

2 participants