bizley / yii2-migration

Yii 2 Migration Creator And Updater
Apache License 2.0
291 stars 36 forks source link

[Feature] Different timestamp for migration file names as Yii operates on time and breaks the migration processes #142

Closed karolls closed 3 years ago

karolls commented 3 years ago

Is your feature request related to a problem? Please describe.

Yii2 uses a migration file timestamp to differentiate migrations. Probably this is more Yii2 related issue however since noone knows if and how it's going to be resolved, would be nice to implement a solution in yii2-migration.

When running a command for all or multiple tables:

php yii migration/create "*"

it is almost certain that the generated migrations will look like (with the same timestamp):

m210820_055600_001_create_table_A
m210820_055600_002_create_table_B
m210820_055600_003_create_table_C
...
m210820_055600_010_create_table_X

Now let's say you will run:

php yii migrate/mark m210820_055600_010_create_table_X

or

yii migrate/mark "2021-08-20 05:56:00"

Since Yii2 operates on timestamps it will loop through migrations comparing only timestamp (210820_055600) and breake the process after marking the first migration which timestamp matches. So in example above only migration m210820_055600_001_create_table_A will be marked as done and placed in migration table and none after it. This is not right.

There is the same problem with running yii migration related commands:

yii migrate/mark 150101_185401
yii migrate/mark "2015-01-01 18:54:01"
yii migrate/mark m150101_185401_create_news_table
yii migrate/mark 1392853618

and

yii migrate/to 150101_185401
yii migrate/to "2015-01-01 18:54:01"
yii migrate/to m150101_185401_create_news_table
yii migrate/to 1392853618  

Describe the solution you'd like

Would be nice as a feature to add a parameter for migration/create and migration/update to add a delay between generating each migration files not to collide with same timestamp:

yii migration/create "*" --delay
yii migration/update "*" --delay

Describe alternatives you've considered

Any other solution making it possible to generate multiple migration files with different timestamps.

bizley commented 3 years ago

Hm, I totally forgot about that feature of Yii, thank you for reminding me. Yes, this needs to be redone. I would rather automatically set timer "in the past" for the ones within the same second.

karolls commented 3 years ago

I would rather automatically set timer "in the past" for the ones within the same second.

Yes but can be tricky as you can collide with some migration in the past. Let's say you have migration in the past that create a table and now you are generating migrations that one of the new ones update this table. Update migration time can't be set before the create migration. Not highly probable in real life, but still.

bizley commented 3 years ago

You are again right. Need to think of something clever.