-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support running multiple statements per migrations file #3693
Comments
Here is a link to the docs this is talking about: https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-MULTI-STATEMENT I have been reading up on the internals chapter of the manual lately and had been a bit confused, because I remembered a sentence that suggested differently (and I accidentally had skipped over the section just below that, that explains the thing with the transactions).
I would prefer using On that topic, it might be a good idea to rename If it is expected, or at least possible that more directives are added in the future it would be nice for them to have a consistent format and be clearly attributable to Also it would make it easier to add snippets for them into code editors ... |
I'm fine with any name 😄 |
Another question is: do we want to support |
I don't think it would be very hard. The way your PR works just isn't good for Wouldn't it be better to split the migrations as they are read from the Implementing it on the level of sqlx/sqlx-core/src/migrate/source.rs Lines 57 to 145 in f6d2fa3
|
I thought of that but we'd have to add a suffix to the version or something |
Yeah you are right. And adding it would sadly break SemVer, because I guess in this case it might genuinely better to wait for |
I have found these related issues/pull requests
#3181 introduced a
--no-transaction
directive specifically so that things likeCREATE INDEX CONCURRENTLY
orCREATE DATABASE
could be run on Postgres.Description
But if you include more than one statement in a query Postgres starts an implicit transaction, which means that you can only run a single statement per migration file. This quickly becomes frustrating.
Prefered solution
I propose the addition of a
-- sqlx: split migration
directive that allows doing something like this:Then sqlx literally calls
split()
on the migration string and runs multiple queries instead of a single one.Is this a breaking change? Why or why not?
I don't think it has to be.
The text was updated successfully, but these errors were encountered: