Skip to content

Variables and secrets

Scripts can use variables with psql's syntax, so scripts written for psql run unchanged:

Syntax Becomes
:'name' a string literal: 'it''s'
:"name" a quoted identifier: "my table"
:name the value as is
CREATE ROLE api LOGIN PASSWORD :'api_password';

Nothing is substituted inside strings, comments or PostgreSQL $$ bodies, and unknown names are left alone, so ::int casts and := assignments are safe.

Where values come from

  1. Declare the variables in the manifest: variables: [api_password].
  2. For each environment, project.yaml says which environment variable holds the value:

    environments:
      - name: PROD
        variables:
          api_password: FINANCE_PROD_API_PASSWORD
    
  3. Without a mapping, the value comes from SQL2DEVOPS_VAR_<NAME> (for example SQL2DEVOPS_VAR_API_PASSWORD).

  4. --var-env name=ENV_VAR overrides it on exec, package run, deploy, promote and emergency.

In a pipeline these environment variables come from its secrets.

Never exposed

Values are never written to the control repository, the history table or any file, and they are masked (****) in every message and failure report. Reports show the script as written, with the variable references.

psql meta-commands

\set ON_ERROR_STOP on is ignored, because Sql2DevOps always stops at the first error. Other psql meta-commands are refused with a clear message: use variables instead of \set.