User Guide: Developer SCM Packaging


Note

This information is now maintained in the product documentation: Placing Files in the SCM Repository

Source Code Management (SCM) Mode

Getting files from an SCM system directly makes it easy to process files as they are checked in without any additional intervention required. Once SQL scripts are checked in to the SCM repository, the user can manually start the Deployment Packager via the Datical DB GUI or CLI. It can also be automatically invoked through SCM polling or an SCM trigger in an automated build solution.

Given the higher level of automation available in SCM Mode, there are a few additional steps that must be taken in order to supply the necessary metadata the Deployment Packager requires to successfully process SQL scripts.

Types of Database Changes

DDL - Data Definition Language

CREATE, ALTER, DROP, COMMENT, RENAME

DML - Data Manipulation Language

INSERT, UPDATE, DELETE, TRUNCATE, MERGE, SELECT

DCL - Data Control Language

GRANT, REVOKE

Stored Logic

CREATE (OR REPLACE) / DROP PACKAGE, PACKAGE BODY, PROCEDURE, FUNCTION, TRIGGER 

Source Control Operations in the Packager

SCM OperationResult in Datical DB Packager

Check-In New File

  • The Datical DB packager will process the sql script as a new file and add the changes in the Datical DB changelog.xml file.

Rename File

  • The Datical DB packager will process the sql script with the new filename.
Move File
  • Moving a file more than once before calling the Datical Packager could cause errors.

Defining Labels in SCM Check In Comments

The Datical DB packager will automatically parse the source control commit message, identify strings enclosed by square brackets, and use the strings as labels for the associated sql scripts.

For example, if a developer checked in a SQL script with the comment

"Add a new column foo to the table bar [label1,label2] [label3]"

then, the Deployment Packager would parse

"label1", "label2", and "label3" 

from the comment and add them as labels to the Change Set(s) associated with the file(s) retrieved from the SCM repository.

Automatically associating Rollback files with sql scripts

To include a rollback file for a given script, name the file containing the rollback script the same name as the change script appended with "-rollback" or "_rollback". For example, if the name of the script is AddMiddleNameColumnToAccountTable.sql, then the rollback file would be named either AddMiddleNameColumnToAccountTable-rollback.sql (with a dash) or AddMiddleNameColumnToAccountTable_rollback.sql (with an underscore).

SQL Script Directory Structure in the Development SCM

In order to associate a script with a particular type of content, SQL scripts should be placed in specifically named directories under the root directory of the SQL code repository. The expected directory structure is documented below. For organizational purposes, the directories can contain sub directories but the top level directory structure must be created as documented if you are using a fixed folder configuration.  (There is also the option of using a flexible folder configuration where you can name the folders to whatever names you prefer.)

sql_script_scm_root_dir
> archive
> data_dml
> ddl
> ddl_direct
> function
> package
> packagebody
> procedure
> sql_direct
> trigger
> view


SCM Directory Name

Description

sql_script_scm_root_dir

The SQL script repositories root directory. Name is defined by the user.
e.g., "sql_code"

archive

The archive directory is created and managed by the Deployment Packager. Files added in the ddl, sqlfile, sqlPlus and data_dml directories will be copied here after successful Packaging to prevent post Packaging modification. The user does not need to create this directory.

data_dml

Contains scripts that load, manipulate or delete data.

ddl

Contains scripts that make ddl changes such as creating, modifying and dropping tables, indexes, sequences, etc.  By default this folder uses packageMethod=convert.

ddl_directContains scripts that make ddl changes such as creating, modifying and dropping tables, indexes, sequences, etc.  By default this folder uses packageMethod=ddl_direct.

function

Contains scripts that create new or replace existing functions.

package

Contains scripts that create new or replace existing package definitions.

packagebody

Contains scripts that create new or replace existing package bodies.

sql

Contains SQL scripts that don't cleanly map to any other category. This scripts will be run as is using an internal SQL executor (JDBC).

sql_direct

Oracle and SQL Server only. The same behavior as scripts in the 'sql' folder, except these scripts will be deployed using the database's native loader (such as sqlplus for Oracle and sqlcmd for SQL Server).

sqlplus(obsolete) Oracle only. The same behavior as scripts in the 'sql' folder, except these scripts will be deployed using Oracle's native loader - sqlplus.
triggerContains scripts that create new or replace existing trigger definitions.
viewContains scripts that create new or replace existing view definitions.
table updated in November 2021

Datical Packaging Methods

  • Convert SQL Scripts
    • This is the default method used for any change placed in the /ddl folder
    • It utilizes a diff process to capture the changes from the supplied SQL scripts and create them as detailed change sets in the Datical changelog.xml file
    • Datical DB can then execute Forecast and Customer Rules against these detailed change sets
  • Native SQL Scripts
    • This method is used for all other packaging folders
    • It does not require the diff process. Because of this, the packaging process is faster
    • The limitation is that Datical DB only supports limited execution of Forecast and Customer Rules against these change sets

Order of Execution in SCM Mode

Deployment Packager in SCM Mode follows 3 ordering tiers for automating the execution order of new SQL scripts:

Tier 1:  Commit Sequence

    • Files in earlier commits will be processed ahead of files in subsequent commits
    • If the same file was modified in a later commit, it's most recent state will be used, but it will be processed in the order of the original commit

Tier 2:  File Type Sequence

Order of execution for a single commit will process as follows:

SCM Directory NameDatical Packaging MethodRefactoringArchived?
ddlConvert SQL Scriptsassorted refactorings based on diff processYes
ddl_directNative SQL Scriptssqlplus (Oracle), sqlcmd (SQL Server), edbplus (Postgres EnterpriseDB), or clpplus (DB2) refactoringYes
viewNative SQL Scriptsview refactoringNo
functionNative SQL Scriptsfunction refactoringNo
procedureNative SQL Scriptsprocedure refactoringNo
packageNative SQL Scriptspackage refactoringNo
packagebodyNative SQL Scriptspackagebody refactoringNo
triggerNative SQL Scriptstrigger refactoringNo
sqlNative SQL Scriptssqlfile refactoring uses JDBCYes
sqlplusNative SQL ScriptsObsolete: sqlplus refactoring (Oracle only)Yes
sql_directNative SQL Scriptssqlplus (Oracle), sqlcmd (SQL Server), edbplus (Postgres EnterpriseDB), or clpplus (DB2) refactoringYes
data_dmlNative SQL Scriptssqlplus (Oracle), sqlcmd (SQL Server), edbplus (Postgres EnterpriseDB), or clpplus (DB2) refactoringYes

table updated on 1/2/2018

Tier 3:  Filename Sequence

If multiple files are included in the same commit, and in the same directory, then files will be executed in alphabetical filename order

Packaging Guidelines

General Notes

  • Don't use Datical DB to create databases or schema. Create them outside of Datical DB.
  • Always store files as UTF8 encoding.

Object Specific Notes

Object TypeNotes

Inserts, Updates and Deletes (DML)

  • All data related scripts should be placed in the "/data_dml" folder.

Procedures, Functions, Views and Triggers

  • It's common for developers to want to manage some database changes like they manage their source code.

    • In this scenario, developers can maintain procedures, functions, views and triggers in their respective folders with one object per file.

    • When a change is needed, developers can simply modify the script and commit the change to source control. 

    • Datical will pick up the file and package it for deployment. 

    • The file will remain in the directory after packaging.

    • The file SHOULD be named the same as the object name for ease of maintenance

  • Developers should create the objects with the CREATE <object> syntax.

    • Datical DB will automatically convert the CREATE to an ALTER, if needed, so permissions are maintained on the object when deployed.

Complex/Interdependent Database Changes

Typically, DDL changes will be placed in the "/ddl" folder. The exception to this is when you need to package/deploy complicated interdependent db changes such as the example below. In this case, place these scripts into the "/sql_direct" or "/ddl_direct" folder.

create table
move data from old table to new table
drop old table
All RENAMEsObject renames need to be placed in the "/sql" or "/sql_direct" or "/ddl_direct" folder so they are processed as renames (instead of DROP and CREATE)
Scripts with Datical PropertiesIf your scripts need to take advantage of Datical Properties, then those scripts must be placed in the "/sql" folder. (by the end of Q4 2017 you will also be able to place them in the "sql_direct/" folder)
All Other Changes

All other database objects should be placed in the "/ddl" or "/ddl_direct" or "/sql_direct" folders as shown in the table.

Copyright © Datical 2012-2020 - Proprietary and Confidential