deltasql Server allows developers to submit their SQL scripts in a central place. Each time a script is submitted, deltasql assigns a number to it (the script's version). Database administrators can check at which version the database table is, by checking the last inserted row in the table TBSYNCHRONIZE. They also can look at the project name in this table. They can then ask the deltasql Server for the currently missing scripts.

With deltasql: A developer sends the script to the deltasql server only, the exact database state is always known and can be synchronized to any state.
When scripts are sent, a database module has to be chosen. A project can consist of one or several modules, as in some companies, they tipically use a three-level structure for their source code modules. The first database module is the lowest level and represents tables which are common for all projects in a company. The middle database module represents the tables of the application which is sold. The highest level module contains tables which are needed for the customization of one particular customer, and which are not needed for other customers.
For simple applications, it is enough to specify one module for each project, although deltasql was developed as help in a much more complex development environment.
deltasql also supports database branches, which are similar to source code branches. It is possible to choose, if a script belongs also to a particular branch. And it is possible to update a branch database to a newer branch, or to the development schema represented by the branch named HEAD.
deltasql Server is written in such a way, that clients can interface to it and query the database automatically. Deltasql is currently shipped with a Java client called dbredactor that is able to interface with mySQL, Oracle, and postgreSQL databases. People in the Open Source community are encouraged to write their own clients, or to partecipate in improvements of the server itself.

Without deltasql: A developer has to send his/her scripts to everyone, the exact database state is known only to the database owner.
If you find the project useful, or if you use deltasql for managing your Open Source project, you are encouraged to add this button
to your homepage. Link it to the project wiki at http://www.deltasql.org/wiki/.This might bring some additional traffic and maybe involve others in the project who will improve the quality of this software. Thanks!
deltasql runs on Apache webserver with the PHP module backed by a mySQL database.
Therefore, you should first download from the Apachefriends.org website XAMPP, a package which bundles Apache, mySQL and phpMyAdmin (and more... :-) for Linux and Windows. deltasql was developed with XAMPP 1.5.5, but any newer version might work as well. Then you should install XAMPP. Using the XAMPP Control Panel start Apache and mySQL.
Download the deltasql PHP scripts, unzip them and copy
them to the htdocs directory created by XAMPP, so that you get a htdocs/deltasql directory
full of PHP scripts.
If you visit the main page index.php, there is a link called Please Setup Deltasql.... Click on this link and follow the instructions there. Set a password for the admin user of deltasql. If you installed XAMPP, you do not need to define a mySQL password for the root account, as XAMPP sets the empty password for root by default. Else please use the correct root password of mySQL. Pressing the "Submit" button will install everything you need to run your deltasql server.
If something should go wrong, you can read also through the next section.
Go to the directory htdocs/deltasql/config, take example_config.inc.php, copy it to
config.inc.php. Edit the variables in config.inc.php depending on your hardware
and network configuration.
As next step, you should visit http://localhost/phpmyadmin, to access phpMyAdmin,
an interface that speaks with the mySQL database. In phpMyAdmin, create a user delta_user with a password you can set in htdocs/deltasql/conf/config.inc.php.
If the deltasql server is published on the Internet, you should also modify the constant $dns_name with the IP number of your
computer or with its DNS name.
Now take htdocs/deltasql/db/script.sql and go back to
http://localhost/phpmyadmin.
Execute the SQL script with the phpMyAdmin interface. It will create a deltasql database.
Log as Administrator with username admin and password testdbsync, so that you can create your own users. Do not forget to change the admin password shortly after with this form.
Download first dbredactor.zip from the deltasql main page (at the bottom!). Unzip the file in the Eclipse workspace. Add the build.xml into the Ant window by right clicking and choosing 'Add build files...'. Copy sample-build.properties to build.properties and set the correct URL for the deltasql server in the deltasql.server.url property. Create in the /config directory a configuration for the database schema as they are done under /config/examples. Next, update config.set with the path to the directory you created.

If everything is configured correctly, you'll be able to check if a schema update is needed with a double click on the ant target dbsync info and to get the script needed to update with dbsync update.
Download first ant-client.zip from the deltasql main page (at the bottom!) and unzip it somewhere. This zip file contains only two tiny files: deltasql-build.xml and sample-deltasql.properties.

Copy deltasql-build.xml into the Eclipse project where you are working (at best in the root directory of the Eclipse project). Add the deltasql-build.xml file into the Ant window by right clicking and choosing 'Add build files...'. Copy sample-deltasql.properties to deltasql.properties. Read through deltasql properties and adjust all properties. Create a lib folder in the Eclipse project (if not already there) and copy all the .jars you can find in the clients\java\dbredactor\lib directory of this package (or only the ones you enabled in deltasql.properties, at your wish).
Et voilą, now you should have a working ant client. By pressing on "RetrieveUpdates" you will receive the script with the latest db updates. The ant client is also easy to integrate in an existing build.xml!

To install the Google Gadget is fairly simple: just click on the following button:
.
A new page will open. Follow instructions there to get the deltasql gadget on your iGoogle start page.
After that, the Google Gadget still points to the deltasql server which is used as showcase for new users. With the arrow that points down on the top right of the deltasql gadget, you should choose the menu entry "Change settings", and enter an URL that points to your local deltasql install. Look at the screenshot:

Finally, remember to save your settings. If deleting cookies forces you to reenter each time a new URL, just modify the default_value string in deltasql/deltasql_google_gadget.xml.
For an explanation of what coloured rows in the gadget mean, see this F.A.Q. question.
There are four types of users: Guests, Developers, Project Managers and Administrators. Guests can only browse through project's scripts, search among them and compute synchronizations for schemas. Developers can do everything Guests can do, but they also can submit new scripts, and edit old ones. Project Managers can create projects and add modules. They can create branches as well. Administrators can add new users to the deltabase.
Developers submit scripts which belong to a module. A project consists of one or several modules. A database schema is always related to a single project. To each script a unique version number is assigned. If a database shows a given version in TBSYNCHRONIZE, deltasql can compute which scripts are necessary to reach another version.
Normally, database schemas and in particular development ones, need the entire chain of module-related scripts to be updated. This chain, as in the everywhere known Control Version System (cvs), is called HEAD. However, deltasql allows to create and name branches for a project. Once a branch is created, developers can choose if a particular scripts belongs only to HEAD, or if it belongs also to the newly created branch. Internally, deltasql simply stores the version number when the branch was created.
When updating with the form, one has to choose the target branch. The target branch can be HEAD, if all scripts need to be executed, and therefore if the database schema has to get a development one. Specifying a new target branch which is not HEAD will update the database schema to the version number assigned to this branch (by inserting a new row in TBSYNCHRONIZE with the version number), no matter if the source branch is the same branch, or if it is a previous one. In principle, it is also possible to update a long forgotten development schema (source branch = HEAD), to another target branch.
Login first with a user which has 'Project Manager' or 'Administrator' rights.
Define a module 'mymodule' with Create DB Module. Then define a project 'myproject' with Create a project. Under List projects it is possible to add the module 'mymodule' to the project 'myproject' with the link 'Add Module'.
Now choose 'Table' under List projects. Specify your database type. This will generate a table which needs to be created in all involved database schemas, you would like to keep under version control with deltasql. Create this table in these database schemas with a sql client.
Developers can now submit scripts with this form. They have to choose to which module the script belongs. If branches are created, they can also choose if a script is only a script for development schemas (a HEAD script), or if it needs to be applied to a previously created branch. They can list all previously submitted scripts. In this list, they can also modify a submitted script, if it contains errors, or if it is incomplete.
To update a database schema with the submitted scripts, you should first query the database schema with SELECT * FROM TBSYNCHRONIZE ORDER BY VERSIONNR DESC. Retrieve in the first row the project name (in PROJECTNAME column), its current version (in VERSIONNR) and its source branch value (in BRANCHNAME). The source branch value HEAD is used for development schemas. For production databases (typically installed to a customer), the source branch value can be the value set when a branch is created. Just look at the first row and disregard the other rows, they are kept so that you have a little bit history of what happened to that database schema (it can be helpful in case you run a script intended for another schema by mistake).
Once the three parameters are retrieved from the database schema, it is possible to ask for a database synchronization with the form Synchronize database schema. The field 'From:' should be filled with the value found in TBSYNCHRONIZE.BRANCHNAME. The field 'To:' (the so called target branch) should be decided as follows: choose HEAD if you would like to update a development schema (= 'From: HEAD') or if you would like to turn a production schema (= 'From:'= name of a created branch) into a development schema. Choose defined branch name for the 'To:' field, if you would like to update a production schema with scripts sent to the production branch, or if you would like to update an older development schema to a newer production branch.
Synchronize database schema will return a page with the missing SQL scripts for that given database schema. Choose 'Edit->Select All' from your browser and then 'Edit->Copy'. Paste the script into your favourite SQL client, which is connected to the database schema and execute it.
The script from Synchronize database schema will create at the end an UPDATE statement, which will update the information in TBSYNCHRONIZE for the next time.
Please note, that if something goes wrong, deltasql server reports an error according to the following list.
This is deltasql in short. Have fun!
With deltasql it is also possible to keep a collection of scripts which are occasionally used for maintenance tasks. It is sufficient to create a database module with a name like 'collection of scripts for myProject' without adding the module to any project. Modules which are not added to a project do not partecipate in the synchronization process. So you can submit maintenace scripts to this module without fear that they will appear in the synchronization sequence. Typically, you will change the default title db update to what the script effectively does. deltasql underlines titles which are not default and allows to search also in the title field of a script.
By using the function Search among scripts, you can then specifically select the module 'collection of scripts for myProject' to search among the maintenance SQL scripts.
When listing scripts (in List Scripts), it is possible to filter the scripts (e.g. by date, module, author and more) by using the command Search among scripts on top of the page. Normally, the scripts are filtered and shown as a list. By checking the checkbox Output as text list before clicking on Submit, the scripts will be shown as a normal text file that can be copy pasted into your SQL client of choice. This can be sometimes useful, if you need to repair a database schema by performing this special operation.
First, it is important to understand that deltasql does not support branches of branches. This keeps things easy.
The main synchronization logic is contained in the file dbsync_update.inc.php. The main query that drives HEAD to HEAD, or BRANCH to BRANCH updates is: (we call it the "standard query")
SELECT DISTINCT s.* from tbscript s, tbscriptbranch sb where
(s.versionnr>$fromversionnr) and (s.versionnr<=$toversionnr) and
(s.module_id in
(select module_id from tbmoduleproject where project_id=$projectid)
and (s.id=sb.script_id) and (sb.branch_id in ($includeheadid, $frombranchid, $tobranchid)))
The query shows that the table tbscriptbranch contains a relation between a given script (stored in tbscript) and the branches (stored in tbbranch) to which it was submitted. tbbranch contains a particular row named HEAD, too. Therefore also the HEAD is represented as a row in tbbranch and can be considered logically as a branch. $frombranchid and $tobranchid are equal in case of a BRANCH to BRANCH update or in case of a HEAD to HEAD update. In both cases, $includeheadid is empty and not used.
$fromversionnr is the value as it is retrieved in the table TBSYNCHRONIZE, and represents the current synchronization point of the database schema. $toversionnr is the version number of the latest script on deltasql, when HEAD is the target branch, or the version number when the BRANCH was created when BRANCH is the target.
In case of a HEAD to BRANCH update, the variable $addbranchscriptsafterbranch is set to 1 and therefore an additional query is done after the standard query (please see the source code to see the query). The standard query adds the HEAD scripts between the current synchronization point on the schema and the point where the branch was created on deltasql. The additional query simply adds all further BRANCH scripts after the branch was created. We call this additional query the "final query". For the standard query, the variable $includeheadid is empty and not used.
The table tbmoduleproject contains the relation between modules and one project. $project_id contains the value of the project we would like to synchronize. Therefore, the query selects only scripts that belong to modules of the project to be synchronized.
In case of a BRANCH to HEAD update, the variable $addheadscriptstoupdatedbranch is set to 1 and thefore an additional query is done before the standard query (also here, please see the source code to see the query). This additional query adds all HEAD scripts between the BRANCH creation point and the current synchronization point on the schema. We call this additional query the "initial query". For the standard qury, the variable $includeheadid is empty and not used.
The most complex case is a BRANCH to NEW_BRANCH update. Both $addheadscriptstoupdatedbranch and $addbranchscriptsafterbranch are set to 1: the "initial query" adds all HEAD scripts between the synchronization point on the schema and the creation point of BRANCH. The standard query does a HEAD to HEAD update between the creation point of BRANCH and NEW_BRANCH (this time the standard query has the variable $includeheadid set to the id of the row named HEAD in the table tbbranch. After that, the "final query" adds all NEW_BRANCH scripts between the creation of NEW_BRANCH and the current HEAD on deltasql.
If you install deltasql with the option Test System (with Test data), you can verify the deltasql correctness with this file.
deltasql Server is written in PHP and can run whenever Apache runs. You might want to write your own deltasql client that integrates better into your own development environment. A client called dbredactor for the Java environment can be download on the bottom of the main page.
A deltasql client should perform the following operations:
This can be simply done by executing the query SELECT * FROM TBSYNCHRONIZE ORDER BY VERSIONNR DESC. The query is so simple as the table has one row per update which was already done. The latest database update has the highest version number. The important columns in this row are PROJECTNAME, VERSIONNR and BRANCHNAME. As you can imagine, PROJECTNAME is the name of the project of this database schema and VERSIONNR is the number of the latest script executed in this database schema. BRANCHNAME tells if the database schema is a development schema (if the value is HEAD), or if it is a production branch. If it is a production branch, the value will be the name of the branch.
If you prefer a query that returns only the row of interest, you might use this one:
select * from TBSYNCHRONIZE where versionnr = (select max (versionnr) from TBSYNCHRONIZE);
The client should touch the URL below and store the resulting page in a file called projectversion.properties. The parameter project in the URL is the value PROJECTNAME retrieved in step one.
http://127.0.0.1/deltasql/dbsync_automated_currentversion.php?project=TestProject
In the projectversion.properties file, there will be a line project.version= which contains the current latest version on deltasql server for this project. The client should now compare the latest version on deltasql and the VERSIONNR value in the database schema and decide if it is necessary to continue with step 3. If not, the user should be informed that there is no new version, that the datamodel did not change since last time.
The client should now ask the deltasql server for the script to be executed in the database schema. It should touch the URL below and store the result as text in a file script.sql, for example.
http://127.0.0.1/deltasql/dbsync_automated_update.php?project=TestProject&version=22&frombranch=TST1&tobranch=HEAD
project is the PROJECTNAME column retrieved in step one and version is the column VERSIONNR. frombranch is the value stored in BRANCHNAME. tobranch should be HEAD if you want to upgrade a schema (branch or development) to the latest development scheman. It should be set to the value contained in BRANCHNAME if the production schema is updated without becoming a development schema. If the parameters frombranch or tobranch are not specified, they default to HEAD.
The parameters described in the previous paragraph are the most important ones, but there are more here, to allow customization and even XML export. If something goes wrong, deltasql server reports an error according to the following list.
Depending if your client includes drivers that are capable of executing complex scripts like packages and stored procedures (JDBC drivers are not), you can either directly execute script.sql in the database schema or show the script to the user and ask him/her to execute it.
The script always contains an UPDATE statement, that sets the new version and branch into the table queried in step one.
The structure itself is described in this text file.
The entire list is here.
If you need help in setting up your own deltasql server, you can contact us at the deltasql mailing list. We appreciate your feedback.
Have fun!