Kind: SGScript
listKind: SGScriptList
plural: sgscripts
singular: sgscript
shortNames sgscr
The SGScript
custom resource represents an ordered list of versioned SQL scripts.
Example:
apiVersion: stackgres.io/v1beta1
kind: SGScript
metadata:
name: script
spec:
managedVersions: true
continueOnError: false
scripts:
- name: create-stackgres-user
scriptFrom:
secretKeyRef: # read the user from a Secret to maintain credentials in a safe place
name: stackgres-secret-sqls-scripts
key: create-stackgres-user.sql
- name: create-stackgres-database
script: |
CREATE DATABASE stackgres WITH OWNER stackgres;
- name: create-stackgres-schema
database: stackgres
scriptFrom:
configMapKeyRef: # read long script from a ConfigMap to avoid have to much data in the helm releasea and the sgcluster CR
name: stackgres-sqls-scripts
key: create-stackgres-schema.sql
See also SQL Scripts section.
Property |
Required |
Updatable |
May Require Restart |
Type |
Description |
---|---|---|---|---|---|
apiVersion | ✓ | string | stackgres.io/v1 | ||
kind | ✓ | string | SGScript | ||
metadata | ✓ | ✓ | object | Refer to the Kubernetes API documentation for the fields of the metadata field. |
|
spec | ✓ | ✓ | object |
|
|
status | ✓ | object |
|
Property |
Required |
Updatable |
May Require Restart |
Type |
Description |
---|---|---|---|---|---|
continueOnError | ✓ | boolean |
If true , when any script entry fail will not prevent subsequent script entries from being executed. false by default.
|
||
managedVersions | ✓ | boolean |
If true the versions will be managed by the operator automatically. The user will still be able to update them if needed. true by default.
|
||
scripts | ✓ | []object |
A list of SQL scripts.
|
Scripts are executed in auto-commit mode with the user postgres
in the specified database (or in database postgres
if not specified).
Fields script
and scriptFrom
are mutually exclusive and only one of them is required.
Property |
Required |
Updatable |
May Require Restart |
Type |
Description |
---|---|---|---|---|---|
database | ✓ | string |
Database where the script is executed. Defaults to the postgres database, if not specified.
|
||
id | ✓ | integer |
The id is immutable and must be unique across all the script entries. It is replaced by the operator and is used to identify the script for the whole life of the SGScript object.
|
||
name | ✓ | string |
Name of the script. Must be unique across this SGScript.
|
||
retryOnError | ✓ | boolean |
If not set or set to false the script entry will not be retried if it fails.
When set to This is |
||
script | ✓ | string |
Raw SQL script to execute. This field is mutually exclusive with scriptFrom field.
|
||
scriptFrom | ✓ | object |
Reference to either a Kubernetes Secret or a ConfigMap that contains the SQL script to execute. This field is mutually exclusive with script field.
Fields |
||
storeStatusInDatabase | ✓ | boolean |
When set to true the script entry execution will include storing the status of the execution of this
script entry in the table managed_sql.status that will be created in the specified database . This
will avoid an operation that fails partially to be unrecoverable requiring the intervention from the user
if user in conjunction with retryOnError .
If set to This is |
||
user | ✓ | string |
User that will execute the script. Defaults to the postgres user.
|
||
version | ✓ | integer |
Version of the script. It will allow to identify if this script entry has been changed.
|
||
wrapInTransaction | ✓ | string |
Wrap the script in a transaction using the specified transaction mode:
If not set the script entry will not be wrapped in a transaction
|
Reference to either a Kubernetes Secret or a ConfigMap that contains the SQL script to execute. This field is mutually exclusive with script
field.
Fields secretKeyRef
and configMapKeyRef
are mutually exclusive, and one of them is required.
Property |
Required |
Updatable |
May Require Restart |
Type |
Description |
---|---|---|---|---|---|
configMapKeyRef | ✓ | object |
A ConfigMap reference that contains the SQL script to execute. This field is mutually exclusive with secretKeyRef field.
|
||
secretKeyRef | ✓ | object |
A Kubernetes SecretKeySelector that contains the SQL script to execute. This field is mutually exclusive with configMapKeyRef field.
|
A ConfigMap reference that contains the SQL script to execute. This field is mutually exclusive with secretKeyRef
field.
Property |
Required |
Updatable |
May Require Restart |
Type |
Description |
---|---|---|---|---|---|
key | ✓ | string |
The key name within the ConfigMap that contains the SQL script to execute.
|
||
name | ✓ | string |
The name of the ConfigMap that contains the SQL script to execute.
|
A Kubernetes SecretKeySelector that contains the SQL script to execute. This field is mutually exclusive with configMapKeyRef
field.
Property |
Required |
Updatable |
May Require Restart |
Type |
Description |
---|---|---|---|---|---|
key | ✓ | string |
The key of the secret to select from. Must be a valid secret key. |
||
name | ✓ | string |
Name of the referent. More information. |
Property |
Required |
Updatable |
May Require Restart |
Type |
Description |
---|---|---|---|---|---|
scripts | ✓ | []object |
A list of script entry statuses where a script entry under .spec.scripts is identified by the id field.
|
Property |
Required |
Updatable |
May Require Restart |
Type |
Description |
---|---|---|---|---|---|
hash | ✓ | string |
The hash of a ConfigMap or Secret referenced with the associated script entry.
|
||
id | ✓ | integer |
The id that identifies a script entry.
|