graphile/migrate

beforeAllMigrations and afterAllMigrations actions are running multiple times

PizzaPartyInc opened this issue · 1 comments

Hi,

This behavior is only reproducible when you have more than 1 migration and have shadow property as true or not defined.
Does not seem like an expected behavior, but if it is, please let me know :)

graphile-migrate version is 0.3.1.

Config examples and logs below:

Config:

    beforeAllMigrations: [
      {
        _: 'command',
        shadow: true,
        command: `echo --------------------------BEFORE`,
      },
    ],
    afterAllMigrations: [
      {
        _: 'command',
        shadow: true,
        command: `echo --------------------------AFTER`,
      },
    ],

commit:

graphile-migrate[shadow]: dropped database 'test_database_shadow'
graphile-migrate[shadow]: recreated database 'test_database_shadow'
--------------------------BEFORE

graphile-migrate[shadow]: Running migration '000001-initial-schema.sql'
graphile-migrate[shadow]: Running migration '000002-second_migration.sql'
--------------------------AFTER

graphile-migrate[shadow]: 2 committed migrations executed
graphile-migrate: New migration '000003-third_migration.sql' created
--------------------------BEFORE

graphile-migrate[shadow]: Running migration '000003-third_migration.sql'
--------------------------AFTER

graphile-migrate[shadow]: 1 committed migrations executed
graphile-migrate: Running migration '000003-third_migration.sql'
graphile-migrate: 1 committed migrations executed

uncommit:

graphile-migrate: migration 'path_to_project/migrations/committed/000003-third_migration.sql' undone
graphile-migrate[shadow]: dropped database 'test_database_shadow'
graphile-migrate[shadow]: recreated database 'test_database_shadow'
--------------------------BEFORE

graphile-migrate[shadow]: Running migration '000001-initial-schema.sql'
graphile-migrate[shadow]: Running migration '000002-second_migration.sql'
--------------------------AFTER

graphile-migrate[shadow]: 2 committed migrations executed
--------------------------BEFORE

--------------------------AFTER

graphile-migrate[shadow]: Already up to date

Config (both shadow and regular):

    beforeAllMigrations: [
      {
        _: 'command',
        command: `echo --------------------------BEFORE`,
      },
    ],
    afterAllMigrations: [
      {
        _: 'command',
        command: `echo --------------------------AFTER`,
      },
    ],

commit:

graphile-migrate[shadow]: dropped database 'test_database_shadow'
graphile-migrate[shadow]: recreated database 'test_database_shadow'
--------------------------BEFORE

graphile-migrate[shadow]: Running migration '000001-initial-schema.sql'
graphile-migrate[shadow]: Running migration '000002-second_migration.sql'
--------------------------AFTER

graphile-migrate[shadow]: 2 committed migrations executed
graphile-migrate: New migration '000003-third_migration.sql' created
--------------------------BEFORE

graphile-migrate[shadow]: Running migration '000003-third_migration.sql'
--------------------------AFTER

graphile-migrate[shadow]: 1 committed migrations executed
--------------------------BEFORE

graphile-migrate: Running migration '000003-third_migration.sql'
--------------------------AFTER

uncommit (This one seems ok):

graphile-migrate: migration 'path_to_project/migrations/committed/000003-third_migration.sql' undone
graphile-migrate[shadow]: dropped database 'test_database_shadow'
graphile-migrate[shadow]: recreated database 'test_database_shadow'
--------------------------BEFORE

graphile-migrate[shadow]: Running migration '000001-initial-schema.sql'
graphile-migrate[shadow]: Running migration '000002-second_migration.sql'
--------------------------AFTER

graphile-migrate[shadow]: 2 committed migrations executed
--------------------------BEFORE

--------------------------AFTER

graphile-migrate[shadow]: Already up to date

This is expected because commit actually wipes the shadow database before it starts:

graphile-migrate[shadow]: dropped database 'test_database_shadow'
graphile-migrate[shadow]: recreated database 'test_database_shadow'

then it migrates to bring up to the currently expected state:

--------------------------BEFORE

graphile-migrate[shadow]: Running migration '000001-initial-schema.sql'
graphile-migrate[shadow]: Running migration '000002-second_migration.sql'
--------------------------AFTER

graphile-migrate[shadow]: 2 committed migrations executed

(For the normal (not shadow) database it won't happen because the DB should already be up to date.)

Next up we do the commit (creating the file):

graphile-migrate: New migration '000003-third_migration.sql' created

And then we migrate again:

--------------------------BEFORE

graphile-migrate[shadow]: Running migration '000003-third_migration.sql'
--------------------------AFTER

graphile-migrate[shadow]: 1 committed migrations executed

Now shadow migration is all good, we know it's safe to commit to the normal database:

graphile-migrate: Running migration '000003-third_migration.sql'
graphile-migrate: 1 committed migrations executed