Include and Exclude Stuff from the Output

How to see why certain tables or columns for excluded

Re-run SchemaCrawler with -loglevel=ALL on the command-line.

[top]

How to include or exclude certain tables or columns

Change the configuration for the SchemaCrawler the table or column include and exclude patterns in the schemacrawler.config.properties file. The include or exclude specification is a Java regular expression . The include pattern is evaluated first, and the exclusions are made from the included tables or columns list.

Also see the filtering and grep command-line options.

[top]

How to exclude database views from the output

Change the configuration for the SchemaCrawler table types to schemacrawler.table_types=TABLE in the schemacrawler.config.properties file.

The option in the configuration can be overridden by the -table_types command-line option. Further, see the details on the command-line options.

[top]

How to exclude stored procedures from the output

Change the configuration for the SchemaCrawler stored procedures to schemacrawler.show_stored_procedures=false in the schemacrawler.config.properties file.

The option in the configuration can be overridden by the -show_stored_procedures command-line option. Further, see the details on the command-line options.

[top]

Create diff-able Output

How to sort columns, foreign-keys and indices alphabetically

Change the configuration for the SchemaCrawler "sort alphabetically" properties in the schemacrawler.config.properties file.

[top]

How to diff column data types across databases

Change the configuration for the SchemaCrawler schemacrawler.format.show_standard_column_type_names=true in the schemacrawler.config.properties file. This setting will show standard data types across different database systems. On the other hand, if you want to see the real database specific data types, change the setting to a value of true.

[top]

How to allow diffs of tables that have columns added in between

When columns are added into a table, they can change the column ordinal number. This can mess up the diffs. Change the configuration for the SchemaCrawler schemacrawler.format.show_ordinal_numbers=false in the schemacrawler.config.properties file. You can combine this setting with the setting to sort columns alphabetically to produce diff friendly output.

[top]

How to hide primary key, foreign key and index names

If primary key, foreign key and index names are not explicitly provided while creating a schema, most database system assign default names. These names can show up as spurious diffs in SchemaCrawler output. Change the configuration for the following properties in your schemacrawler.config.properties file.

schemacrawler.format.hide_primarykey_names=false
schemacrawler.format.hide_foreignkey_names=false
schemacrawler.format.hide_index_names=false
schemacrawler.format.hide_constraint_names=false
[top]

Integrations

How to script with your database metadata

When SchemaCrawler is used with J2SE 6 and above, it has built-in support to be used with JavaScript scripts. Write a JavaScript file, assuming that a "catalog" variable containing the database schema will be available. Run schemacrawler.tools.integration.scripting.Main , with the correct options. See the example in the examples\javascript directory for more details.

[top]

How to create your own output format

SchemaCrawler integrates with Apache Velocity to allow for templated ouput. Put Velocity on your classpath, and create your template, and run schemacrawler.tools.integration.velocity.Main , with the correct options. See the Velocity example in the _distrib\velocity directory for more details.

[top]

How to create a database diagram of your schema

SchemaCrawler integrates with Graphviz to produce graph images. Install Graphviz, and run schemacrawler.tools.integration.graph.Main , with the correct options. See the graphing example in the _distrib\graphing directory for more details.

[top]

How to Use SchemaCrawler in Projects

How to use SchemaCrawler programmatically

Read Java API Makes Database Metadata as Easily Accessible as POJOs for an introduction to the SchemaCrawler API. (This article may refer to an older release of the SchemaCrawler API, but the concepts are the same.) You can also browse the javadocs .

See the example in the _distrib\examples\api directory.

Or, if you are impatient, try code similar to the following:

SchemaCrawlerOptions options = new SchemaCrawlerOptions();
Catalog catalog =
  SchemaCrawlerUtility.getCatalog(connection, options);
for (Schema schema: catalog.getSchemas())
{
  System.out.println(schema);
  for (Table table: schema.getTables())
  {
    System.out.println("o--> " + table);
    for (Column column: table.getColumns())
    {
      System.out.println("     o--> " + column);
    }
  }
}

[top]

How to use SchemaCrawler as an ant Task

SchemaCrawler comes with a full-featured ant task.

See the example in the _distrib\examples\ant-task directory.

In addition to the ant task parameters mentioned in the example, you may find the following parameters useful.

  • config Path to the configuration file (default value - schemacrawler.config.properties)
  • config-override Path to the configuration override file (default value - schemacrawler.config.override.properties)
  • db-driver-classpath Database driver classpath (default value - value of the ant property value ${db-driver-classpath})
  • datasource Datasource defined in the configuration (either the datasource, or the connection properties should be provided - if both sets are provided, the datasource is ignored)
  • driver JDBC driver class name
  • url Database connection string
  • user Database connection user name
  • password Database connection password (default value is an empty string)
  • command Comma-separated list of commands
  • no-header Whether to print the header - true or false (default value - false)
  • no-footer Whether to print the footer - true or false (default value - false)
  • no-info Whether to print information - true or false (default value - false)
  • outputformat Output format (default value - text)
  • outputfile Path to output file
  • append Whether to append to the output - true or false (default value - false)
[top]

How to use SchemaCrawler To Produce a Maven Report

SchemaCrawler comes with a Maven reports plug-in. You can generate a SchemaCrawler report along with other reports for your Maven generated site.

See the example in the _distrib\examples\maven directory.

Install the SchemaCrawler Maven plug-in by running the following command, and following the instructions that are printed out. java -cp schemacrawler-6.3.jar schemacrawler.tools.integration.maven.Main

Next, add a section to your Maven 2.0 project's pom.xml file, similar to that below, changing what needs to be changed:

<reporting>
  <plugins>
    <plugin>
      <groupId>schemacrawler</groupId>
      <artifactId>schemacrawler-maven-plugin</artifactId>
      <version>4.0</version>
      <configuration>
        <schemacrawler.config>schemacrawler.config.properties</schemacrawler.config>
        <schemacrawler.datasource>hsqldb</schemacrawler.datasource>
        <schemacrawler.command>verbose_schema</schemacrawler.command>
        <schemacrawler.outputformat>html</schemacrawler.outputformat>
        <schemacrawler.jdbc.driver.classpath>hsqldb.jar</schemacrawler.jdbc.driver.classpath>
      </configuration>
    </plugin>
  </plugins>
</reporting>

Run mvn site . See the output produced in the target/site directory of your project.

[top]