Copyright 2009 AB Grund-Data
Sollentuna, Sweden 2009-10-27
Dzo is a database utility which helps to maintain databases.
The goal with dzo is to treat an applications database objects the
same way the applications source code is treated, in respect to
development, revision control and deployment.
Dzo uses a textfile which contains native create-statements for all
database objects and compare against the actual database-schema.
As a result dzo create the sql-statements that is needed to update the
database-schema (or you can let dzo execute the sql-statements directly).
If your application lives in a tomcat- or jboss-container dzo has a
servlet that control the deployment process, undeploy old application,
inspect and execute the needed database changes and finally deploy
the new application.
Dzo works at the moment with database-engines:
- mySql
- Oracle
- Sql Server
The documentation of dzo consists of the file doc/dzo-user-se.odt (there is
also a pdf to download) but unfortunatly (due to my lousy english) this
document only exists i swedish. But hey, swedish is not that hard to learn.
There is also a quick reference card in english.
Files in the distribution (X is revision):
readme-en-X.txt This file
release-notes-en-X.txt Release-notes for revisions
dzo-user-se-X.pdf Users manual for dzo (in swedish)
dzo-quickreference-en-X.pdf A quick reference for dzo
dzo-src-X.zip Source code in zip format
dzo-src-X.tar.gz Source code in gzipped tar format
dzo-X.jar The jar-file
dzo-X.jar now have a simple swing-application. Start it with:
java -jar dzo-X.jar
Now you can generate files like the servlet and samples-files.
In the tab Laborate you can experiment with dzo.
To try the dzo-servlet (chapter 8) you need:
- A local mysql running.
- In mysql do "grant all privileges on *.* to dzodba@localhost identified by 'dzodba';"
- set the environment variable CATALINA_HOME to tomcat:s home-directory
- Copy mysql jdbc-driver to tomcat:s CATALINA_HOME/shared/lib
- A local tomcat running.
- The jar-utility in your PATH (or a JRE 1.5/1.6)
To install the servlet do:
servletdzo
or in unix/linux
sh servletdzo
Pack the simple application named dzoapp. The script takes the database-script file3.sql
and packs it with a simple dzo.xml which points out database dzoappdb.
instdzoapp
or in unix/linux
sh instdzoapp
Now you can open a browser and type in url "http://localhost:8080/dzo" and start playing.
When you have updated the database you can change the script file3.sql and run instdzoapp
again and do a new Compare.
A small example for mysql:
If your database-schema look like this:
----------------------------------------------------------------------------
create database test;
create table person
(
id int(8),
name varchar(20),
shoesize int(2) not null
)
type=innodb;
create index person_i1 on person(name);
----------------------------------------------------------------------------
And you have a file with this content (add a primary key, new column age,
extend column name to 40 characters, index person_i1 is not needed any
longer and add a new index person_i2):
----------------------------------------------------------------------------
create database test;
create table person
(
id int(8) primary key,
name varchar(40),
age int(3),
shoesize int(2) not null
)
type=innodb;
create index person_i2 on person(shoesize);
----------------------------------------------------------------------------
dzo will create the following sql-statements:
----------------------------------------------------------------------------
drop index person_i1 on person
runTheSql
alter table person add column age int(3)
runTheSql
create index person_i2 on person(shoesize)
runTheSql
alter table person add constraint person_pk primary key(id)
runTheSql
alter table person modify column id int(8)
not null
runTheSql
alter table person modify column name varchar(40)
runTheSql
alter table person modify column age int(3)
after name
runTheSql
----------------------------------------------------------------------------