-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql/migrate: handle partially applied checkpoint files
- Loading branch information
Showing
2 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
internal/integration/testdata/mysql/cli-migrate-apply-checkpoint-fail.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
only mysql | ||
|
||
atlas migrate hash | ||
|
||
# There will be an implicit commit in MySQL, leaving this file partially applied. | ||
! atlas migrate apply --url URL | ||
stderr 'executing statement "THIS IS A FAILING STATEMENT;" from version "3"' | ||
|
||
# Status will tell us about partial appliance. | ||
atlas migrate status --url URL | ||
stdout 'Migration Status: PENDING' | ||
stdout ' -- Current Version: 3 \(1 statements applied\)' | ||
stdout ' -- Next Version: 3 \(1 statements left\)' | ||
stdout ' -- Executed Files: 1 \(last one partially\)' | ||
stdout ' -- Pending Files: 1' | ||
stdout '' | ||
stdout 'Last migration attempt had errors:' | ||
stdout ' -- SQL: THIS IS A FAILING STATEMENT;' | ||
|
||
# Running apply again with fixed file will solve it, only running the missing statement. | ||
cp 3_checkpoint.sql migrations/3_checkpoint.sql | ||
atlas migrate hash | ||
atlas migrate apply --url URL | ||
stdout 'Migrating to version 3 from 3 \(1 migrations in total\):' | ||
stdout '' | ||
stdout ' -- migrating version 3' | ||
stdout ' -> CREATE TABLE `tbl_2` \(`col` bigint\);' | ||
stdout ' -- ok' | ||
|
||
atlas migrate apply --url URL | ||
stdout 'No migration files to execute' | ||
|
||
-- migrations/1_first.sql -- | ||
CREATE TABLE `tbl_1` (`col` bigint); | ||
|
||
-- migrations/2_second.sql -- | ||
CREATE TABLE `tbl_2` (`col` bigint); | ||
|
||
-- migrations/3_checkpoint.sql -- | ||
-- atlas:checkpoint | ||
|
||
CREATE TABLE `tbl_1` (`col` bigint); | ||
THIS IS A FAILING STATEMENT; | ||
|
||
-- 3_checkpoint.sql -- | ||
-- atlas:checkpoint | ||
|
||
CREATE TABLE `tbl_1` (`col` bigint); | ||
CREATE TABLE `tbl_2` (`col` bigint); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters