Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to synchronize development and production database

Do you know any applications to synchronize two databases - during development sometimes it's required to add one or two table rows or new table or column. Usually I write every sql statement in some file and during uploading path I evecute those lines on my production database (earlier backing it up). I work with mySQL and postreSQL databases.

What is your practise and what applications helps you in that.

like image 642
pbrodka Avatar asked Nov 01 '08 18:11

pbrodka


People also ask

How do I keep my database synced?

In order to keep your databases in relevance you have to add, delete, and update these correspondent records in destination database. Insert Sync, Update Sync and Drop Sync options checked all together allow you getting entirely identical source and target databases.


3 Answers

You asked for a tool or application answer, but what you really need is a a process answer. The underlying theme here is that you should be versioning your database DDL (and DML, when needed) and providing change scripts to be able to update any version of your database to a higher version.

This set of links provided by Jeff Atwood and written by K. Scott Allen explain in detail what this ought to look like - and they do it better than I can possibly write up here: http://www.codinghorror.com/blog/2008/02/get-your-database-under-version-control.html

like image 166
whaley Avatar answered Sep 21 '22 16:09

whaley


For PostgreSQL you could use Another PostgreSQL Diff Tool . It can diff two SQL Dumps very fast (a few seconds on a db with about 300 tables, 50 views and 500 stored procedures). So you can find your changes easily and get a sql diff which you can execute.

From the APGDiff Page:

Another PostgreSQL Diff Tool is simple PostgreSQL diff tool that is useful for schema upgrades. The tool compares two schema dump files and creates output file that is (after some hand-made modifications) suitable for upgrade of old schema.

like image 35
Patryk Kordylewski Avatar answered Sep 17 '22 16:09

Patryk Kordylewski


Have scripts (under source control of course) that you only ever add to the bottom off. That combined with regular restores from your production database to dev you should be golden. If you are strict about it, this works very well.

Otherwise I know lots of people use redgate stuff for SQLServer.

like image 27
Iain Holder Avatar answered Sep 19 '22 16:09

Iain Holder