While infer_schema! and friends support postgres schemas, they only do so statically; i.e., you specify that for database foo you want the tables from schema bar using infer_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.
I'm not sure I see much value in doing this over specifying the schema in the table! call, and just glob-importing that module where needed. Can someone elaborate more on the use case?
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 (SET search_path on connection). There main roadbump is that database setup doesn't work, as it ignores the schema.
There main roadbump is that database setup doesn't work, as it ignores the schema.
I ran into that exact problem today. Hence, I am wondering: is there any workaround to have src/schema.rs generated when using a dedicate schema and the search_path URL trick?
Stumbled on this today. Adding ?application_name=my_app&options=-c search_path%3Dmy_app to the connection string as suggested in the article as well as specifying schema in diesel.toml seems to do what I want.
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 !
Most helpful comment
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 (
SET search_pathon connection). There main roadbump is that database setup doesn't work, as it ignores the schema.