I might even just move the whole thing into a command for more control (and less hacky testing). You'll have to move some of this migration code outside this file anyways since IIRC, you can't define a task within a migration.