This question is specific to Sqitch, but may have relevance with other database migration management tools.
The first Sqitch change in my application defines its general schema: it creates all my tables tables and defines their columns.
Let's say that first change is named appschema
, and that one of the tables it creates is lessons
with columns chapter
, section
, and title
.
Now, a couple already-deployed changes later, I want to drop the title
column from the lessons
table.
I run sqitch add move_lesson_titles_out_of_db
and write that change's deploy
script as
ALTER TABLE lessons DROP COLUMN title;
I sqitch deploy
that to my local dev target and it works as expected.
But now, sqitch verify dev
fails, because the appschema
change's verify script looks to confirm the title
column exists. Up until now I'd been able to run sqitch verify dev
and all previous changes would pass. Perhaps it's my misunderstanding, but I'd been under the impression that all changes should continue to verify when run in order on properly-deployed and up-to-date Sqitch target.
I could sqitch rework appschema
instead of adding a change, but Sqitch documentation is very clear that both the original and reworked change must be idempotent, and since appschema
contains a bunch of CREATE TABLE
s, it is already not idempotent. Furthermore, if I understand sqitch correctly, to deploy this reworked appschema
would revert all my changes (since it is the first change in my Plan), back to an empty database, then replay everything back.
I would end up with the correct schema, but at the cost of erasing all data. Obviously, not something I plan to do on my production target.
Is there a better method to add a change which drops a column, without dooming sqitch verify
to fail on the earlier change which created that column? Or is this verification failure by design?
If by design, is there any way I can still benefit from verifying the many other things the appschema
change does that haven't subsequently changed (namely, the defining the entire rest of my app's schema)?