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

Open
killercup opened this Issue Jul 26, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@killercup
Member

killercup commented Jul 26, 2017

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.

@killercup killercup added the postgres label Jul 26, 2017

@sgrif

This comment has been minimized.

Member

sgrif commented Aug 5, 2017

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?

@skade

This comment has been minimized.

skade commented Aug 6, 2017

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.

@lthms

This comment has been minimized.

lthms commented Sep 8, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment