-
Notifications
You must be signed in to change notification settings - Fork 116
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
Migrator truncates phinxlog of migration sets whose tables are not dropped. #603
Comments
I took some time to look at this tonight and I'm not sure there is a feasible solution for this other than to throw errors when The problem boils down to Because we don't have enough metadata to know which tables map to which phinxlog tables, and which migrations within those migration logs we can only operate on schema and phinxlogs in a coarse manner. You might be able to get the results you're looking for by using |
Applying `skip` to multiple profiles when using `runMany()` creates a problem that I don't think is solvable. The problem boils down to skip is able to exclude some or all tables from a migration set (plugin or application). When we're attempting to reset both table schema and phinxlog state we can only operate at the connection level. Because both your plugin and application are using the same connection the queries we need to use to find which tables need to be dropped and which phinxlogs need to be reset pollute each other and overlap. Because we don't have enough metadata to know which tables map to which phinxlog tables, and which migrations within those migration logs we can only operate on schema and phinxlogs in a coarse manner. Refs #603
Applying `skip` to multiple profiles when using `runMany()` creates a problem that I don't think is solvable. The problem boils down to skip is able to exclude some or all tables from a migration set (plugin or application). When we're attempting to reset both table schema and phinxlog state we can only operate at the connection level. Because both your plugin and application are using the same connection the queries we need to use to find which tables need to be dropped and which phinxlogs need to be reset pollute each other and overlap. Because we don't have enough metadata to know which tables map to which phinxlog tables, and which migrations within those migration logs we can only operate on schema and phinxlogs in a coarse manner. Refs #603
Sorry for late response. The problem is truncating same connection multiple times. migrations/src/TestSuite/Migrator.php Lines 94 to 96 in b1b1459
|
@nishimura-d That does look incorrect. I can get that condition and the related one for connectionsToDrop but those changes don't seem to change the behavior in a way that will address this issue as the test added in #604 is still passing which means the migration application failed. |
This logic has been wrong since skip options were added. Refs #603
This logic has been wrong since skip options were added. Refs #603
Yes, the Expected Behavior is not achieved. Once #607 is merged, I will write: (new Migrator())->runMany([
[],
['plugin' => 'TestPlugin'],
]);
This behavior is fine. Since my misunderstanding has been resolved, I am fine with closing this issue as is. BTW, about "the test added in #604". $migrator->runMany([
['plugin' => 'Migrator', 'skip' => ['migrator']],
]); This would be the same. migrations/tests/test_app/Plugin/Migrator/config/Migrations/20211001000000_migrator.php Line 9 in f262d6f
That's why migrations/src/TestSuite/Migrator.php Lines 124 to 125 in f262d6f
I don't think this message is appropriate. In my example, I skip tables that are not in each migration set. |
What would make more sense to you?
Sounds good. I agree that |
How about this? If you are using the |
That works for me too. Did you want to put a pull request together for that? If not I'll get to this eventually. |
No. I don't have enough time to make a pull request, sorry. |
This is a (multiple allowed):
bug
CakePHP Version: 4.4.6
Migrations plugin version: 3.6.0
Database server (MySQL, SQLite, Postgres): MySQL 8.0.29
PHP Version: 8.1.14
Platform / OS: Linux
What you did
users
) and theTestPlugin
plugin (createtest_plugin_entities
).tests/bootstrap.php
:Expected Behavior
All runs succeed.
On second run,
TestPlugin
tables are not dropped.On third and forth runs, no tables are dropped.
Actual Behavior
Second run failed:
TestPlugin
tables are not dropped, buttest_plugin_phinxlog
is empty.Third run failed:
phinxlog
is empty.Forth run succeeded.
TestPlugin
tables are dropped and re-created by migrations.Cause
migrations/src/TestSuite/Migrator.php
Lines 217 to 220 in 792cc07
This truncates
phinxlog
of unrelated migration sets.Workaround
This problem doesn't occur if we don't use the
skip
option, but tables are truncated twice in one run.The text was updated successfully, but these errors were encountered: