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¶
- Declare the variables in the manifest:
variables: [api_password]. -
For each environment,
project.yamlsays which environment variable holds the value:environments: - name: PROD variables: api_password: FINANCE_PROD_API_PASSWORD -
Without a mapping, the value comes from
SQL2DEVOPS_VAR_<NAME>(for exampleSQL2DEVOPS_VAR_API_PASSWORD). --var-env name=ENV_VARoverrides it onexec,package run,deploy,promoteandemergency.
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.