项目作者: qwazer

项目描述 :
Command line util for export IBM DB2 schema to set of ddl scripts
高级语言: Java
项目地址: git://github.com/qwazer/db2-scheme2ddl.git
创建时间: 2015-03-21T06:03:57Z
项目社区:https://github.com/qwazer/db2-scheme2ddl

开源协议:

下载


Download Build Status

Description

db2-scheme2ddl - command line util for export IBM DB2 schema to set of ddl scripts. Provide a lot of configurations via basic command line options or advanced XML configuartion.

:warning: Keep in mind, that db2-scheme2ddl build around undocumended SYSPROC.DB2LK_GENERATE_DDL procedure. So use it on your own risk.

Benefits

db2-scheme2ddl give ability to filter undesirable information, separate DDL in different files, pretty format output.

How to start with minimal configuration

Java must be installed on your computer.
For exporting db2 scheme you must provide

  • DB connection string
  • output directory

Usage example. Command

  1. java -jar db2-scheme2ddl.jar -url scott/tiger@localhost:5000:SAMPLE -o C:/temp/db2-scheme/

will produce directory tree

  1. SCHEMA1/
  2. views/
  3. view1.sql
  4. view2.sql
  5. tables/
  6. table1.sql
  7. functions
  8. /f1.sql

More command line options

  1. java -jar db2-scheme2ddl.jar -help
  2. ...
  3. Options:
  4. -help, -h print this message
  5. -url, DB connection URL
  6. example: scott/tiger@localhost:5000:SAMPLE
  7. -o, --output, output dir
  8. -p, --parallel, number of parallel thread (default 4)
  9. -s, --schemas, a comma separated list of schemas for processing
  10. -c, --config, path to scheme2ddl config file (xml)
  11. --stop-on-warning, stop on getting DDL error (skip by default)
  12. -tc,--test-connection, test db connection available
  13. -version, print version info and exit

How it is work inside?

  1. First, get list of all schemas from command line parameter, from congif or find all available schemas with query

    1. SELECT table_schem from SYSIBM.SQLSCHEMAS
  2. Invoke undocumented DB2 function for every schema

    1. CALL SYSPROC.DB2LK_GENERATE_DDL('-e -z SAMPLE', ?)
  3. store second INOUT parameter for later use
  4. find primary object’s DDL with query

    1. select OP_SEQUENCE, SQL_STMT, OBJ_SCHEMA, OBJ_TYPE, OBJ_NAME, SQL_OPERATION
    2. FROM SYSTOOLS.DB2LOOK_INFO
    3. where OP_TOKEN=? and OBJ_SCHEMA=?
    4. and OBJ_TYPE=? and OBJ_NAME=?
  5. find depended object’s DDL with additional filter parameter. For example, find indexes of table

    1. SELECT *
    2. FROM SYSTOOLS.DB2LOOK_INFO t
    3. WHERE OBJ_TYPE = 'INDEX'
    4. AND OP_TOKEN = ?
    5. AND exists(
    6. SELECT 1
    7. FROM SYSCAT.INDEXES i
    8. WHERE TABSCHEMA = ? AND TABNAME = ? AND i.INDNAME = t.OBJ_NAME )
  6. find grants from syscat.*auth tables, convert table rows to sql statements (Incomplete and potentially buggy code)

  7. call SYSPROC.DB2LK_CLEAN_TABLE for every schema to clean temp data

Unfortunately, SYSPROC.DB2LK_GENERATE_DDL doesn’t accept -x parameter for DB version 9.7