Open febpetroni opened 7 months ago
Hi @febpetroni
I think this behavior is expected.
prefer-robust-statements works on a single file level. The rule ensures that the statements in a file can be run multiple times in case of a partial failure.
If a file only has one statement, it can be run multiple times without issue.
If there are multiple statements, then more care is needed. Either wrapping a transaction or adding an if not exists
clause
Hi @chdsbd , thanks for the quick response!
I think I understand what you mean... if you're using a migration tool, like flyway, a one-line migration will either work and be persisted (so that it won't actually run again), or will fail and must be fixed; meanwhile for migrations with more than one line and without transactional scope, we will have partial commits that won't let us run the whole migration again.
I had the impression that prefer-robust-statements
would ask to use if exists
/ if not exists
as a good practice, regardless of the number of lines in the migration. Thanks for clarifying!
Version: v0.24.2
Config file:
Migration file 1:
Output:
Expected:
Migration file 2:
Output:
Expected:
However, if both statements are in the same migration file, it works as expected:
Migration file 3:
Output (as expected):