Prerequisites
-------------

1) Java SDK 1.3 or higher
2) Apache Ant for build ( http://ant.apache.org/) if you want to build from source

Getting the code
----------------

svn checkout http://www.nitrc.org/svn/hid/utilities/trunk/utilities/dbutils

Building 
--------

in $DBUTILS_HOME Run 

ant

to compile


Preparation for usage
---------------------
Assuming the full path to the directory you have checked out dbutils package as $DBUTILS_HOME

1) create and set the environment variable DBUTILS_HOME to the  full path to the directory you have checked out dbutils package

export DBUTILS_HOME=<full-path-to_dbutils-root-directory>

2) Copy $DBUTILS_HOME/conf/dbutils.properties.example to $DBUTILS_HOME/conf/dbutils.properties and edit the database host, database user/schema name and database user password portions. 
Also set for each table which needs to have a column type changed, you need to specifiy the table name, column name, and new column type. An example is shown 
below

table1.name=t_test1
table1.column=conceptid
table1.columntype=varchar2(64)

table2.name=t_test2
table2.column=conceptid
table2.columntype=varchar2(64)

Here two tables having their concept id types changed to varchar2(64).

3) Run 
  $DBUTILS_HOME/bin/fix_col_types.sh

This will backup the data in each table with a column type change to a temporary file, drop the corresponding foreign keys, delete all the data in the table with a column type change, change the column type, put back the data from the temprary table, check if data is succesfully copied over, drop the temporary table and write the foreign key add/drop script for the table to users home directory as <tablename>fk.sql file. Use the <tablename>fk.sql scripts add foreign key table section in SQLPLUS to put back the dropped foreign keys.



Database Export
---------------

Connects to a HID database and exports all the data from the tables with names starting with NC_ and
dumps insert statements for each table so that you can connect to another Oracle database with the same
schema via SQLPlus and run the insert statements to create a snapshot of the exported database.

Make sure that the triggers are disabled or dropped before you import data to an empty HID database and
enable (put) the triggers back after the import

Usage
-----

1) create and set the environment variable DBUTILS_HOME to the  full path to the directory you have checked out dbutils package

export DBUTILS_HOME=<full-path-to_dbutils-root-directory>

2) Copy $DBUTILS_HOME/conf/dbexporter.properties.example to $DBUTILS_HOME/conf/dbexporter.properties and edit the database host, database user/schema name and database user password portions.

3) run
$DBUTILS_HOME/bin/db_export.sh > db_snapshot.sql
For Oracle to Postgres migration
$DBUTILS_HOME/bin/db_export.sh postgres > db_snapshot.sql


4) Connect to the empty HID instance via SQLPlus and run

spool import.log
@db_snapshot.sql
spool off



WHAT'S NEW
----------
A list of changes in recent versions

1.1 (17-June-2004)
	- Added Oracle to Postgres export for Database Export functionality.
	Now you can connect to an Oracle db and create insert statements for
	a Postgres database (Mainly tested with UCSD mbirn db and HID schema)


 
