Repository navigation
Conversation
9cbda2f to
e3eb061
Compare
…ition
up ran a file migration as one string inside its transaction, so a failure
said "failed and was rolled back" and nothing else unless PostgreSQL sent a
position. It sends one for expression and cast errors but not for most DDL
and constraint errors, the common failures of a generated file. A file with
twenty statements then named neither the statement nor the line:
migration 0012_hand failed and was rolled back: relation "usrs" does not exist
A transactional file migration now runs its statements one at a time inside
the same transaction. It costs the same, the all-or-nothing rollback is
unchanged, and the statement that raised the error gives both the line and
its text.
A comment before a statement stays with it, so the line is the first that
carries code, not the comment above it. When the driver does send a position,
it is counted from the statement's text, comments included, so the lines
skipped before its code come off before the file's offset is added.
A Go migration and a -- ant:no-transaction file run as before. A file whose
statements Split cannot place in the script runs whole, as it did.
Signed-off-by: Liang Xu <24490353+lx3133584@users.noreply.github.com>
e3eb061 to
761f27d
Compare
|
Thanks, this works, and the tests cover the cases with and without a position. Three small things:
|
…d what running by statement costs lineOfCode skipped blank lines and -- lines only, so a statement under a block comment was reported at the comment's line. It now passes a block comment to where it closes, over the lines it runs and the comments nested in it, as PostgreSQL reads them and as Split keeps them with the statement. The comment on ran() described a branch it does not have: checkBody has refused a file that ends its own transaction before the transaction begins. It and decision 162 also said running statement by statement costs the same. It is one round trip per statement instead of one per file, which a large data migration notices, and both now say so.
|
Thanks, all three are in.
|
…-line # Conflicts: # docs/decisions/README.md
…-line # Conflicts: # docs/decisions/README.md
|
All three are in on the head.
|
upran a file migration as one string inside its transaction, so a failure saidfailed and was rolled backand nothing else unless PostgreSQL sent a position. It sends one for expression and cast errors but not for most DDL and constraint errors, which are the common failures of a generated file. A file with twenty statements then named neither the statement nor the line:A transactional file migration now runs its statements one at a time inside the same transaction. The all-or-nothing rollback is unchanged; the cost is one round trip per statement instead of one per file, which a large data migration notices (5,000 statements over a 1 ms link take about 5 s longer), and the statement that raised the error gives both the line and the text:
A comment before a statement stays with it, so the line is the first that carries code, not the comment above it. That holds for a
--line and for a block comment, over however many lines it runs and whatever it nests. When the driver does send a position it is relative to the statement, so that statement's first line is added.Two paths are unchanged. A Go migration and a
-- ant:no-transactionfile run as before — the first is code, the second has no transaction to run inside. A file whose statementsSplitcannot place in the script runs whole, as it did, so no line is named there unless the driver sends a position.Testing
tests/features/migrations/up_test.gogains these tests:TestFailedMigrationWithoutAPositionruns a file whose second statement names a relation that does not exist, which PostgreSQL reports with no position, and checks the error names line 3 and the statement. It failed before the change with no line at all.TestFailedMigrationUnderACommentputs a comment above the failing statement and checks the line is the statement's own, not the comment's.TestFailedMigrationUnderABlockCommentdoes the same under a three-line block comment with one nested in it: line 3, the comment's, beforelineOfCodeskipped block comments, line 6 after.TestFailedMigrationAfterABlockCommentOnItsLineandTestFailedMigrationWithAPositionUnderABlockCommentpin code on the comment's own line and a driver position under a block comment.TestFailedMigration, which already covered a position case, still reports line 3, so a position within a statement maps back to the right line in the file. Each new behaviour was checked against a mutation that undoes it, and each turned red.make fmt,make lint→ 0 issuesmake test→ no failuresANT_TEST_DATABASES=postgres go test ./tests/features/migrations/ ./migrate/...→ all pass exceptTestCommandsSayWhichMigrations/postgres/a_relative_folder,_from_the_working_directory, which fails the same way on a cleanb1e7568checkoutgo test ./tests/docs→ passes, with the new decision 162Fixes #303