logo

Manual deltasql 1.0.9

Back to main page

Summary

Purpose

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!

Install Guides

Install steps for the Server

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.

Manual install steps for the server

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.

. If you did all steps right, you should get a working deltasql Server as in this webpage if you visit http://localhost/deltasql

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.

Install steps for the dbredactor client (optional step)

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.


Picture: the two Ant targets of dbredactor

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.

Install steps for the ant client into Eclipse (optional step)

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.


Picture: the target of the Ant Client

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!

How to install the Google Gadget (optional step)


Picture: the Google Gadget of deltasql showing the latest submitted scripts

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.

Usage

User Management

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.

deltasql Concepts

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.

Quick Guide

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!

Tips

Define script's collections for maintenance tasks

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.

Filter script - output particular synchronization 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.

Advanced Topics

Insights into the deltasql Algorithm

First, it is important to understand that deltasql does not support branches of branches. This keeps things easy.

If you install deltasql with the option Test System (with Test data), you can verify the deltasql correctness with this file.

How to write your own deltasql client

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:

Directory structure of the deltasql_1.x.y package

The structure itself is described in this text file.

List of error codes for deltasql server

The entire list is here.

Feedback on this document

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!