Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix migrations being run when nothing changes #551

Merged
merged 3 commits into from
May 10, 2022
Merged

Fix migrations being run when nothing changes #551

merged 3 commits into from
May 10, 2022

Conversation

pabloelcolombiano
Copy link
Contributor

@pabloelcolombiano pabloelcolombiano commented May 5, 2022

Fixes #533

@othercorey
Copy link
Member

Can you add a test case for this?

@pabloelcolombiano
Copy link
Contributor Author

pabloelcolombiano commented May 5, 2022

The shouldDropTables method is protected, therefore it cannot be tested as such.

In my original implementation, the migrator had a protected connectionsWithModifiedStatus property, with a public getter. This enables to test if a connection was found as dirty and should be dropped, or not. The test looked like this.

If you are O.K. with adding this property and a getter as described, I would then be able to test this, and also the two cases where a connection should be dropped.

Or do you see an alternative way to test the feature?

@pabloelcolombiano
Copy link
Contributor Author

There is actually a way to test the feature without changing the src code. Simply by performing an insertion before running the migrator, and seeing if the connection gets truncated or not. On my way implementing that...

@markstory
Copy link
Member

Could a test for this be to add a new source directory. Then partially run those migrations, and then use migrator and check its log output? That isn't the best test but it covers the user facing behavior at least.

@pabloelcolombiano
Copy link
Contributor Author

The path I am taking right now is to run the migrator, set the end date of the entry in the phinx log to 'Foo', and re-run the migrator. If the end_date is 'Foo', the migrations were not re-run. if the end_date is now, the migrations were re-run.
Three scenarios:

  • all migrations up -> end_date == 'Foo'
  • some migrations down -> end_date == now()
  • some migrations missing -> end_date = now()

@pabloelcolombiano
Copy link
Contributor Author

The problem I am facing now, is that if we run:

$migrator->runMany([
   ['plugin' => 'Migrator',],
   ['plugin' => 'Migrator', 'source' => 'Migrations2',],
], false);

the first set of migrations sees the migrations of the second set as missing. So the migrations get re-run again.
Scratching my head...

@pabloelcolombiano
Copy link
Contributor Author

I think in this configuration, with several sets of migrations targeting the same migration table, there is no way to avoid that migrations get re-run every time. But this is really a hedge case. This will not re-run the migrations:

$migrator->runMany([
   ['plugin' => 'Migrator',],
   ['source' => '../../Plugin/Migrator/config/Migrations2',],
], false);

@othercorey othercorey changed the title #533 Up migrations should not be reported as problematic, and should … Fix migrations being run when nothing changes May 5, 2022
@othercorey
Copy link
Member

Could a test for this be to add a new source directory. Then partially run those migrations, and then use migrator and check its log output? That isn't the best test but it covers the user facing behavior at least.

Running an integration test for this seems reasonable. We don't always need to test the single function that should affect it.

@pabloelcolombiano
Copy link
Contributor Author

pabloelcolombiano commented May 9, 2022

Running an integration test for this seems reasonable. We don't always need to test the single function that should affect it.

Just to make sure we are on the same page here:
Are any additional tests or actions needed here?
If so, please detail precisely which additional scenario need to be covered. If the tests provided do not match your expectations from an "integration test", let me know which scenario would.

tests/TestCase/TestSuite/MigratorTest.php Outdated Show resolved Hide resolved
@markstory markstory merged commit e1b03bf into cakephp:3.x May 10, 2022
@markstory
Copy link
Member

Thank you 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrator rerunning migrations for testing when nothing added
3 participants