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 Operation | Result in Datical DB Packager |
---|---|
Check-In New File |
|
Rename File |
|
Move File |
|
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. |
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_direct | Contains 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). |
trigger | Contains scripts that create new or replace existing trigger definitions. |
view | Contains 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 Name | Datical Packaging Method | Refactoring | Archived? |
---|---|---|---|
ddl | Convert SQL Scripts | assorted refactorings based on diff process | Yes |
ddl_direct | Native SQL Scripts | sqlplus (Oracle), sqlcmd (SQL Server), edbplus (Postgres EnterpriseDB), or clpplus (DB2) refactoring | Yes |
view | Native SQL Scripts | view refactoring | No |
function | Native SQL Scripts | function refactoring | No |
procedure | Native SQL Scripts | procedure refactoring | No |
package | Native SQL Scripts | package refactoring | No |
packagebody | Native SQL Scripts | packagebody refactoring | No |
trigger | Native SQL Scripts | trigger refactoring | No |
sql | Native SQL Scripts | sqlfile refactoring uses JDBC | Yes |
Obsolete | |||
sql_direct | Native SQL Scripts | sqlplus (Oracle), sqlcmd (SQL Server), edbplus (Postgres EnterpriseDB), or clpplus (DB2) refactoring | Yes |
data_dml | Native SQL Scripts | sqlplus (Oracle), sqlcmd (SQL Server), edbplus (Postgres EnterpriseDB), or clpplus (DB2) refactoring | Yes |
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 Type | Notes |
---|---|
Inserts, Updates and Deletes (DML) |
|
Procedures, Functions, Views and Triggers |
|
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 RENAMEs | Object 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 Properties | If 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