Migration show an error, but applied
For an “up” migration:
If you have any migration files with mismatched file's and class's names, migration will show an error "The migration class "Migration_Class_name" could not be found", but even so will apply, if the broken file's version greater than target version (i.e. we actually don't need to touch the broken file for migrate up to the target).
If you try to migrate through several versions than the broken file can interrupt migration process with error, but all "good" files will work well, so migration version will increase but still be lower than target.
Furthermore, if you try to go back to the last migration's version (I think it's very likely in case you got error), the migration will also show error, and won't make any changes. It's happens because migration files are checked in inverse order, so the broken file is interrupting a migration process before any "good" files can be applied.
The reason in that condition checks all files even if they actually won't been applied.
For a "down" migration the situation are mirrored.
Let me show an example. I will use sequential migrations for simplifying. Let we have 4 migration file — 001-004, where file 003 is broken: it have name “003_Migrate_Create_users_table”, but consist class “Migrate_Broken_users_table”. So, current version is 1, and I want to migrate to version 2. I'm change version in the config file, and then I'm call migration->current(), which show an error, but applied. Now, I want to come back to the previous version. I set version to 1, and run migration->current().I get an error, and no changes were applied — I still have version 2. If I'll try to migrate from version 1 to 4, I’ll get an error too, and actually I'll been migrated to version 2.
This is all very confusing the way you've put it ... let's see if I got it:
- You have migration numbers from 1 to 4
- You want to migrate from 1 to 2, not caring about 3 and 4
- The migration reports an error but still applies the migration version 2 file
Is that correct?
In general, yes. I would go on the list:
- I want to migrate back from 2 to 1.
- The migration reports an error and don't applies, so I still have version 2.
I left those intentionally as they depend on how the other three should work and we need to solve that first. Which brings me to the point - do you expect no migrations to be applied in case of an error? Or that migrations with numbers larger than what you've specified shouldn't be checked at all?
There are valid use cases for both ...
Actually I expect all of this. I understand that the broken migration files is not normal and it's completely my problem, but the way this files can affect on migration process is not clear.
In the documentation says that migration->current() returns
current version string on success, FALSE on failure
So, when I got FALSE from migration->current(), I decide that something went wrong and expected that no changes applied to DB.
What do you mean you expect "all of this"? It's one of two options, they cancel each other.
I mean that in case of an error no migrations must be applied, but no need to check files with numbers larger than what I have specified.
How's that?
Seems pretty good. Thank you.
Well, I know it looks good, but did you test it?
Yes, I did. I was repeat all manipulations that I initially described, and now it's worked clear.
Great then, thanks!