Overview

This page documents the use of admin tools to create or update a DB schema.

This admin tool is used to create the schema (for a new installation) or update it (for a deployment of updated model objects).

Prerequisites

  • MySQL database must already exist (e.g. "mappingservicedb").
  • MySQL database connection parameters must be defined in the properties file specified by "run.config".

Details

This tool is used to create an initial DB schema, or update the schema upon code changes to add or change existing fields.  

NOTE: fields that get removed are not handled by this process nor are declarations of new indexes nor statements in the "import.sql" file. Changes in these resources will require explicit creation in a database that already is instantiated with data.  Additionally, addition of a non-nullable field without a default to a table containing rows already can be problematic.  The typical strategy or adding a non nullable field is this:

  • Add a new field as nullable
  • Set the values appropriately (using an admin task).
  • In a future deployment, update the model to make this field not-nullable.

Following are some details about the implementation of this tool:

Mojo: UpdateDbMojo.java (in admin/mojo/src/main/resources/java/org/ihtsdo/otf/mapping/mojo)

Project: admin/updatedb

Configuration Parameters

  • A profile of "Updatedb" must be specified
  • run.config - the standard configuration file specified as a -D parameter
  • hibernate.hbm2ddl.auto - required parameter should be set to either  "update" or "create"
    • Either not passing this property or passing a different value will cause the tool to have no effect.
    • Update mode will add new fields (which can be problematic if they are declared as nullable=false)
    • Create mode will destroy the existing database and remake it anew, including running statements in the "import.sql" file (in admin/mojo/src/main/resources)

Samples

Sample command line call of the admin tool to create a DB:

% cd ~/code/admin/updatedb
% mvn install -PUpdatedb -Drun.config=~/config/config.properties -Dhibernate.hbm2ddl.auto=create

Sample command line call of the admin tool to simply update an existing DB:

% cd ~/code/admin/updatedb
% mvn install -PUpdatedb -Drun.config=/home/ihtsdo/config/config.properties -Dhibernate.hbm2ddl.auto=update 

 

Sample Eclipse run configuration:

  • n/a

 

 

  • No labels