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

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

Closed
karolls opened this issue Aug 20, 2021 · 3 comments · Fixed by #152

Comments

@karolls
Copy link

karolls commented Aug 20, 2021

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
Copy link
Owner

bizley commented Aug 20, 2021

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
Copy link
Author

karolls commented Aug 20, 2021

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
Copy link
Owner

bizley commented Aug 20, 2021

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

karolls added a commit to karolls/yii2-migration that referenced this issue Aug 24, 2021
…le names as Yii operates on time and breaks the migration processes bizley#142
@bizley bizley mentioned this issue Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants