CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

Feature Request: Migration dependencies

Open MGatner opened this issue 4 years ago • 3 comments

A constant headache, particularly with testing, is running a migration that modifies a table from another migration but that table isn't created yet because the other migration did not run. I would like to see either a "dependency" or "preliminary" migration feature: the former skipping the migration if its parent has not run, the latter running the parent on-demand if it has not yet.

MGatner avatar May 21 '21 18:05 MGatner

@MGatner Do you really need this?

A constant headache, particularly with testing, is running a migration that modifies a table from another migration but that table isn't created yet because the other migration did not run.

I don't understand why this happens.

kenjis avatar Aug 07 '23 22:08 kenjis

All migrations have an ordinal number. How can I skip the creation if you are updating?

neznaika0 avatar Aug 08 '23 03:08 neznaika0

It's been a while since I wrote this but I believe the issue is cross-library. For example, if I want to add a firstname column to my Shield users then in app/Database/Migrations/ I will create a new migration with UPDATE TABLE ADD COLUMN. This will fail, though, if the Shield migrations have not been run - e.g. under testing if I set $namespace = 'App'. This requires the developer either to run all migrations for every test, or keep track of which migrations have these "dependencies".

At this point I think effort would probably be better spent on adding a database state snapshot to our testing workflow. I started work towards this in my Schemas library in the form of "database-structure-to-migration" but never finished. I think it would be a very helpful feature generally, and a huge performance and ease-of-use improvement for testing.

MGatner avatar Aug 08 '23 10:08 MGatner