symfony doctrine:build --all --and-load WITHOUT LOSING RECORDS IN DATABASE
I am new to Symfony+Doctrine, but fairly experienced with web application development in general (mostly using Zend Framework). I have started a new project using Symfony, and I'm loving it.
I've got a handful of fixtures in my /data/fixtures/ folder which get loaded whenever I update the schema and do a:
sf d开发者_运维问答octrine:build --all --and-load
The problem is, adding fixtures is really tedious, whereas my app interface is pretty quick to load data with. So, I load testing data into the database (using my app), but then whenever I make a change to the schema (and run the above statement), it reverts the data to just what's in the fixtures.
In the manual I read that the --and-append option would not overwrite the data in the database. But, the --all option says it resets the database.
Obviously if I delete a column from the schema then I would lose that information, but I just want to preserve my new records.
Sorry if I'm missing something very obvious. Thanks in advance for any help you can provide!
Use symfony doctrine:build --all-classes
From the documentation (symfony help doctrine:build
):
You can also generate only class files by using the --all-classes shortcut
option. When this option is used alone, the database will not be modified.
./symfony doctrine:build --all-classes
I try to make sure my process for schema changes is smooth enough that I will make them as soon as I think they're necessary instead of putting them off. Nuking all the data I've been working with is a definite turn-off that will increase mental resistance and keep me using a problematic schema longer than I should.
So--I think you're doing it right with the fixtures you have, you just need to dump more (symfony doctrine:data-dump
) of your UI-entered data into the fixtures before reloading. You will have to rewrite or rebuild the fixtures for some schema changes, but that's just the way it is. Investing in working fixtures gives you flexibility to make schema changes.
The build --all
drops the database and you lose the information that's in it. the --and-load
loads whatever you have in your fixtures back into it. So as far as I know there isn't a single command to do what you're after. From what I've understood the --and-load
and --and-append
are similar, as you can run doctrine:data-load
repeatedly as well and it won't erase existing data.
So, in short, to keep your data, don't run build --all
but make changes to your database through SQL, update your schema, and then just re-generate the models.
You can make the db changes via doctrine migrations or yourself via sql scripts (which is IMO the safer option) or manually in the DB if you're developing. Typically I just rebuild the model classes to reflect the new schema changes (via doctrine:build) and just do a full db drop and recreate periodically to make sure everything works ok.
精彩评论