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

migration library: specify schema without search path DSN? #603

Open
nexovec opened this issue Sep 19, 2024 · 4 comments
Open

migration library: specify schema without search path DSN? #603

nexovec opened this issue Sep 19, 2024 · 4 comments

Comments

@nexovec
Copy link

nexovec commented Sep 19, 2024

Hi,
is it possible to make migrate do its migration inside a postgres schema and then connect to it with a client without actually spawning an entire new pgxpool(with search_path in the DSN string)?

@bgentry bgentry changed the title client and migration is a schema migration library: specify schema without search path DSN? Sep 20, 2024
@bgentry
Copy link
Contributor

bgentry commented Sep 20, 2024

Search path is currently the only way for the migrator to execute migrations against an alternate schema. I think to do otherwise we would probably need to evolve some sort of string interpolation for schema into our migrations. Might be something we tackle when trying to solve alternate schemas more broadly (there are still a number of other compatibility issues mostly stemming from sqlc not offering a way to inject a schema name dynamically).

@nexovec
Copy link
Author

nexovec commented Sep 22, 2024

@bgentry I think you can do this without modifying existing queries altogether using SET search_path TO <schema> statement (relevant postgres docs). Potentially you wouldn't have to even modify any existing queries with this. I just verified it also affects CREATE/ALTER TABLE. So you could just do that before you migrate and during client tx initialization.

@bgentry
Copy link
Contributor

bgentry commented Sep 24, 2024

That’s going to be a session level change which persists on the connection even after it’s returned in the database pool, right? My understanding is the only way to reliably dynamically change the schema for specific queries is to inject it into the query string.

@nexovec
Copy link
Author

nexovec commented Sep 27, 2024

The effects of SET LOCAL last only till the end of the current transaction, whether committed or not.

There is a way to make it scoped to a transaction, is that applicable?

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

2 participants