This may not be a Symfony question, but I'll post it here anyway. A month from now we will have a half dozen sites like this one, all with their own databases. We are still adding features and changing the database schema on a frequent basis. I know I can use a database migration to update the database for any one Symfony project, but I'm looking for a way to automate this for multiple projects. For now, all of these sites are sitting on one server.
I'm looking for the most specific answer possible. If possible, don't just write something like "Use Cappuccino", instead, if possible, please point me to a specific script that is about updating multiple databases.
Hey Lawrence, ltns. I'm going to have to agree with the illustrious Mr. Wage on this one. You can pretty easily configure Capistrano to run your migrations through Doctrine. (Or you could do it all through ActiveRecord in Rails, of course.) Then you just need to set up your configuration for each server, and then make deploy tasks that run each, or all at once. This might point you in the right direction:
Though, if you're talking about a dozen sites or more, you might want to start doing a convention-over-configuration style system instead - looking for predictably named config files and whatnot. (Btw, Colin Steele has done a bunch with this sort of thing if you don't find your answer here.)
Thanks, Bill. The article on craig-mackenzie.com is really informative. I think I will go with this approach.
I'm not so sure i unsderstood you,but you can to put simple file on each host,and the file will get info from one file on the main server that will send requests to all the files of each site and will update the database
I should preface this by saying I don't have a specific script for you. However, if I was to approach this problem I would do something like this:
1. Implement all your database changes using migrations as you described above.
2. Have a location in your version control system which is used to store 'migrations to be deployed'.
3. Write a symfony task which pulls the migrations to be deployed from your VCS and automatically migrates the database to the latest version. This will be run on your server.
4. Write another symfony task which you run from your dev instance. It should connect to each of your servers via ssh and run the task you wrote in step 3.
Instead of using symfony tasks for everything you could also consider investing some time in choosing and learning a configuration management system. You've got multiple sites that need maintaining; they're on one server now but if you're lucky and these sites take off they may be on their own servers in the future. A good configuration management system will be a tool you will be able to use to solve all kinds of problems of this class.
The one I like is called AutomateIt: http://automateit.org/. It's in Ruby, but the configuration file approach will seem familiar to anyone familiar with symfony. With AutomateIt you can not only script database management tasks, but server configuration tasks like the installation of PEAR/PECL modules.
I would recommend integrating capistrano + svn/git + Doctrine migrations
You use capistrano to basically script the deployment and execution of the migration classes from svn/git across multiple databases servers.
Make a file like this on your server ("migrator.php") and change $root_dirs to match your websites root directories (each symfony project root dir) :
$root_dirs = array(
foreach($root_dirs as $dir)
exec(sprintf("php %s/symfony doctrine:migrate", $dir));
echo sprintf("%d websites database have been updated !\n", count($root_dirs));
Now you can remotly launch that file through SSH for example :
ssh [email protected] 'php /path/to/migrator.php'
I believe that should solve your issue…