Create naming conventions for a template

In this tutorial, you will learn how to annotate an ADM-template with naming-conventions. Take for example a naming-convention that adds a prefix for users (or any other object for that matter) at creation-time. Interested? Let’s get started!

More background information on naming rules is found here: How-to: develop templates

Arrange

  • Have a basic ADM-setup on your Git-repo using for example this guide: How-to: setup Gitlab repository

  • A valid ADM license added to the /environment directory

  • A valid config file - admin_users.yml added to the /input directory

Click to see config file
{
  "template": "create_adm_user.sql.j2",

  "vars": [
    {
      "var_user_name": "RDAALMAN",
      "var_user_email": "rob@acheron.cloud",
      "var_wh_default": "WH_DWH_P_ELT"
    }
  ]
}

Act

Creating users is a frequent action. Instead of typing a USER script over and over again, a template can provide a bit of efficiency gain. Take the following SQL file to create a user. We take this script as starting point to transform into a template.

Listing 1. Config used for creating admin users with naming conventions
{
  "template": "create_adm_user.sql.j2",
  "naming_conventions": {
    "adm_username_convention": "ADM_{{username}}" (1)
  },
  "vars": [
    {
      "var_user_name": {
        "adm_username_convention": {
          "username": "RDAALMAN" (2)
        }
      },
      "var_user_email": "rob@acheron.cloud",
      "var_wh_default": "WH_DWH_P_ELT"
    }
  ]
}
1 Automatically add "ADM_" to username
2 Apply the naming convention

Assert

The Templating stage renders the config into the following SQL:

Listing 2. Generated SQL
/**
 * Derived from template: create_adm_user.sql.j2
 *
 * This script solely creates admin user
 *
 * The default role will be set where the role is created
 *
 * Jinja variables to set:
 *  - var_user_name: STRING e.g. "adm_user"
 *  - var_user_email: STRING e.g. "info@acheron.cloud"
 *  - var_wh_default: STRING e.g. "WH_DEMO"
 **/


/**
 * Prerequisites
 **/
USE ROLE IDENTIFIER('SECURITYADMIN');

/**
 * Create user
 **/
USE ROLE IDENTIFIER('SECURITYADMIN');
  CREATE USER IF NOT EXISTS IDENTIFIER('ADM_RDAALMAN')
    PASSWORD             = '*****'
    COMMENT              = 'ADM account'
    LOGIN_NAME           = 'ADM_RDAALMAN' (1)
    DISPLAY_NAME         = 'ADM_RDAALMAN'
    MUST_CHANGE_PASSWORD = FALSE
    DEFAULT_ROLE         = 'SECURITYADMIN'
    DEFAULT_WAREHOUSE    = 'WH_DWH_P_ELT'
    EMAIL                = 'rob@acheron.cloud'
  ;
GRANT ROLE IDENTIFIER('SECURITYADMIN') TO USER IDENTIFIER('ADM_RDAALMAN');

/**
 * Validation
 **/
  USE ROLE      IDENTIFIER('SECURITYADMIN');
    DESCRIBE USER IDENTIFIER('ADM_RDAALMAN');
1 Notice: the username with the added "ADM_" - 'ADM_RDAALMAN'