views:

329

answers:

2

What's the best way to make small schema updates to your symfony/doctrine application?

My issue is, I'm working on a new side-project and occasionally find myself adding a new column here, a new column there as i find the need. However, my DB already has existing data and I dont want to run a complete rebuild and drop my DB with the changes each time.

I also dont want to write fixtures. They're annoying, and it's much easier to use my application to insert data and keep it around while developing. I also dont want to write a migration to add one or two columns, especially when I'm doing this a lot.

Are my only choices to:

  1. make changes to the schema file and wipe the db after every schema change -or-
  2. update the schema file and manually run alter statements on my db

Ultimately, what I'd like to do is either make changes to my db, and have symfony figure out what the schema file should look like, or make changes to the schema file and have symfony figure out what new changes to make to the existing database.

Please help!

Thanks. First time using SO, can't wait to see if i get a response!

+1  A: 

Look at this post:

http://stackoverflow.com/questions/296078/can-you-generate-a-migration-from-an-existing-table-with-doctrine

and this link: http://www.doctrine-project.org/documentation/cookbook/1%5F0/en/code-igniter-and-doctrine%3Asetup-command-line-interface

We have been generating the changes from doctrine by changing the yaml file, running the doctrine command with generate-migrations-diff option to produce a migration file, then using the migrate option to migrate the change.

Arthur Frankel
A: 

I know exactly what you mean. There are two ways you can tell symfony what your database structure looks like:

  1. Create yaml file -> run build-sql command -> run insert-sql command
  2. Create database within your RDBMS -> run build-schema command

With method 1, your data gets wiped out each time. With method 2, your data remains intact. The only problem with method 2 is that you'll wipe out any doctrine-specific attributes that you had in your yaml file and you'll have to add those back in. To me, though, that's a lot less of a pain in the ass than to have to reload your data into your database.

Jason Swett