Reputation:
I'm currently using SVN for my PHP projects. I was thinking I should get my database under version control too, but what's the best way to do that? Do I just make a db-folder in my project in SVN, paste SQL changes into a file called from_1.0_to_2.0.sql and commit?
Upvotes: 49
Views: 52177
Reputation: 1323055
Note that in December 2012, you had another option: DBV (DataBase Version)
It is based on this Github project (stalled in 2018), and is a database version control web application featuring schema management, revision scripts, and more.
It has been discontinued since early 2021.
Upvotes: 31
Reputation: 2193
Migrations in Laravel - PHP framework seems really useful but there is one big BUT. There is only online tool for designing schema in Laravel ORM language called "Eloquent" (here). So it is still unusable if you need to design and maintain database of some serious project.
Upvotes: 0
Reputation: 621
kdbv may its helpful its upgrade your mysql database to current latest version from older without tracking change in mysql tables
Upvotes: 0
Reputation: 56430
Whenever you make changes to your database, you should save those changes in a migration, that you can then later on run on other servers at the same time you update your code. But you basically got the right idea. You can write some tools to make it more automated; for example version each file, and then create a table like migration_version
in your database, which will contain the current version of the database. You can then create a migrate script that will run all the migrations required to get the database up-to-date.
Note that if you want bi-directional db versioning (so that you can revert back to previous db version too), you need to write the required queries for that too for each version.
There are also some tools that can aid you in writing the migrations, such as MySQLdiff
Upvotes: 23
Reputation: 1970
Check out
http://www.liquibase.org/quickstart
The idea is this:
All database changes are stored in a human readable yet trackable form and checked into source control. - Liquibase.org front page
This is a fantastic piece of software that allows you to version your database, in roughly the same process as the top rated answer, except this wheel has already been written and is ready to roll. I use it at work, it's a fantastic solution. Implement it yourself if you want to learn how it works, but Liquibase works great if you want a tool to get things done.
Upvotes: 13
Reputation: 4039
You can use the MySQL Workbench tool.
The file generated with the modeling tool could esaly be saved under SVN. The tool allows you to synchronise your database with the model in bidirectionnal way.
Upvotes: 1