-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Figure out story for dynamically setting PG schemas #1045
Comments
I'm not sure I see much value in doing this over specifying the schema in the |
The recommended way of sharing a database on many SaaS and multiuser systems where you get one database assigned (such as Heroku) is assigning a schema to each deployed application. This name cannot (reasonably) be picked ahead of time, but can easily be configured as a runtime property. The use case is currently indeed this: sharing a low-tier Heroku database (which costs 50$/month) to multiple mid-traffic applications. In this case, I'd like the user to be able to pick the schema name. To my current understanding, Diesel mostly supports this through the URL trick and could better support it if it did what Rails does ( |
I ran into that exact problem today. Hence, I am wondering: is there any workaround to have |
Stumbled on this today. Adding Should we document the connection string options somewhere ? It seems to have helped several people already. Unless this is completely unintended and likely to break ? |
http://docs.diesel.rs/diesel/pg/struct.PgConnection.html documents what it takes |
My bad, I missed it. Thanks @sgrif ! |
If I specify |
@51yu As this open issue indicates official support for switching schemas via the database url is not provided by diesel, so it is kind of expected that things may not work at all. |
I ran into a related issue where I work on different environments that use different postgres schema names. Therefore I can't hardcode them in my app or use Instead, I have set the -- set search path for a specific role:
alter role my_user set search_path = my_schema;
-- set search path for a specific database:
alter database my_database set search_path = my_schema; In general this works quite well with diesel. I don't need to specify the schema anywhere in my code and also The only exception is I can overwrite which schema is used with When I remove the mod definition and the schema name from all qualified table names, everything works as expected on all environments, since all other processes simply follow My proposal would be to add a new boolean attribute |
You can likely automate that via the
That might be reasonable behavior without the setting. I would be happy to review a PR for that. |
While
infer_schema!
and friends support postgres schemas, they only do so statically; i.e., you specify that for databasefoo
you want the tables from schemabar
usinginfer_schema!("postgres://foo", "bar")
.Another use-case for schemas is to run multiple production apps on the same database, using different schemas. And while it is possible to do this with diesel, it requires hacking around with connection URL parameters, as described by @skade in this post. It's not an indented feature, though, and thus doesn't work with
diesel setup
for example.The text was updated successfully, but these errors were encountered: