Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 29 revisions

DBVersion is a database versioning tool, used to synchronize and keep track of database changes. It can also be used to make sure your development and products database are synchronized! [h2]Installation instructions[/h2] [b]1.[/b] Download DBVersion here: File:dbversionci-0.9.zip, unzip contents to the application folder.

[b]2.[/b] Create an XML file that will be used to store the DB changes. Here's a template file with full syntax: [code] <?xml version="1.0" encoding="UTF-8"?> <![CDATA[ SELECT * FROM any_sql_data ]]>

<version id="2">
    <dropColumn name="table.column" />
</version>
[/code] [b]3.[/b] Check out the configuration file for the CIDBVersion library, point it to the XML file and make sure you have a DB user that can ALTER, CREATE and DROP.

[b]4.[/b] Execute a Dry run of the library, testing what it looks like. Here's an example (from a controller) how to run it: [code] $this->load->library('CIDBVersion'); $this->cidbversion->DryRun(); [/code] [b]5.[/b] If the xml validates and the output looks good, get ready to update! It's very simple as well, here's a code snippet: [code] $this->load->library('CIDBVersion');

if(!$this->cidbversion->LatestDBVersion()) { $this->cidbversion->Synchronize(); } [/code] As you see, the LatestDBVersion() method can be used to test if the DB is up-to-date.

[b]6.[/b] For every change you make on your database, update the XML file with a new version element.

[b]7.[/b] All you need to do to synchronize another database with the DBVersion library installed is just to send the updated XML file to that server, and run Synchronize().

The forum thread for DBVersion is here:[url=http://codeigniter.com/forums/viewthread/69303/]http://codeigniter.com/forums/viewthread/69303/[/url], please post your comments, ideas or other things. Thank you!

Clone this wiki locally