-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Migration example #512 #517
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
Conversation
As suggested in #512, this adds an example of how to use the DoctrineMigrationBundle
Just added more comments and details
|
having a migration starting from an unknown state is a bad idea. This is not the proper usage of the migration library. The first migration should migrate from an empty database so that migration commands are working for everyone. |
|
@stof we may add an example of a migration ... but we don't want to force a useless migration. So we said, imagine that we have a time machine and can go back to the moment before #457 was merged. What would have been the migration created for that change? The idea is to create the migration that we should have done ... but never did. The migration will be only an example to see it but not to execute it. Nobody will have to execute that to make the app runnable. |
|
@stof I agree the migrations should go from empty database to current state. However, I don't see reason why they should not be already applied when a developer clones this repo (except some meaningless migration to serve as example). List of applied migrations is in the database, so it should not cause any problem since the database is distributed with the source code. |
|
@stof I added the migration number to the migration_versions table in both sqlite databases so that the command |
| { | ||
| $this->addSql('ALTER TABLE symfony_demo_user ADD fullName VARCHAR(255) DEFAULT NULL'); | ||
| $this->addSql('UPDATE symfony_demo_user SET fullName = username'); | ||
| $this->addSql('ALTER TABLE symfony_demo_user CHANGE fullName fullName VARCHAR(255) NOT NULL'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apetitpa, this syntax is not supported by sqlite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I'm afraid this is valid for mysql databases only. Do you know how can I achieve the same with sqlite ? From what I read it seems that it is not possible to alter columns definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apetitpa, try to use any string ("Unknown" for example) as a default value:
$this->addSql('ALTER TABLE symfony_demo_user ADD fullName VARCHAR(255) NOT NULL DEFAULT "Unknown"');There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@voronkovich thank you for your help
|
ping @stof @javiereguiluz what about this PR ? |
|
I'm actually -1 on this PR, because it shows an invalid usage of doctrine/migrations. The content of app/DoctrineMigrations assumes that you will do the initial database creation with The right usage of doctrine/migrations is to write the first migration as a migration from the empty database to the needed one (and then never using |
|
Agree with stof |
|
I'll wait for a final word from @javiereguiluz and @jkufner and then I'll close the PR |
|
@apetitpa I can't really add anything here because I don't have much experience with migrations. But if Christophe and Tobias agree that this is the wrong way to use/teach this feature, we can't merge this. It's sad because you spent some time preparing this pull request, but this is something that sometimes happen when contributing to open source projects. I'm sorry. |
|
@javiereguiluz it's ok don't worry, as you said it happens sometimes but it is part of the game and it's for the greater good. Thanks to @stof and @Tobion, Symfony beginners won't be confused about migrations and I think this is the most important point. I close this PR since it won't be merged. Thank you for your time everyone. |
As suggested in #512, this adds an example of how to use the DoctrineMigrationsBundle to apply database migrations.