SGScript


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
Description

Workaround for hugo bug not rendering first table row

apiVersion
string
stackgres.io/v1
Constraints: required, immutable
kind
string
SGScript
Constraints: required, immutable
metadata
object
Refer to the Kubernetes API documentation for the fields of the metadata field.
Constraints: required, updatable
spec
object


Constraints: required, updatable
status
object


Constraints: optional, updatable

SGScript.spec

↩ Parent

Property
Description

Workaround for hugo bug not rendering first table row

continueOnError
boolean
If true, when any script entry fails, it will not prevent subsequent script entries from being executed. false by default.

Constraints: optional, updatable
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.

Constraints: optional, updatable
scripts
[]object
A list of SQL scripts.

Constraints: optional, updatable

SGScript.spec.scripts[index]

↩ Parent

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
Description

Workaround for hugo bug not rendering first table row

database
string
Database where the script is executed. Defaults to the postgres database, if not specified.

Constraints: optional, updatable
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.

Constraints: optional, updatable
Default: -1
name
string
Name of the script. Must be unique across this SGScript.

Constraints: optional, updatable
retryOnError
boolean
If not set or set to false the script entry will not be retried if it fails.

When set to true the script execution will be retried with an exponential backoff of 5 minutes, starting from 10 seconds and a standard deviation of 10 seconds.

This is false by default.


Constraints: optional, updatable
script
string
Raw SQL script to execute. This field is mutually exclusive with scriptFrom field.

Constraints: optional, updatable
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 secretKeyRef and configMapKeyRef are mutually exclusive, and one of them is required.


Constraints: optional, updatable
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 used in conjunction with retryOnError.

If set to true then wrapInTransaction field must be set.

This is false by default.


Constraints: optional, updatable
user
string
User that will execute the script. Defaults to the superuser username when not set (that by default is postgres).

Constraints: optional, updatable
version
integer
Version of the script. It will allow to identify if this script entry has been changed.

Constraints: optional, updatable
wrapInTransaction
string
Wrap the script in a transaction using the specified transaction mode:

  • read-committed: The script will be wrapped in a transaction using READ COMMITTED isolation level.
  • repeatable-read: The script will be wrapped in a transaction using REPEATABLE READ isolation level.
  • serializable: The script will be wrapped in a transaction using SERIALIZABLE isolation level.

If not set the script entry will not be wrapped in a transaction


Constraints: optional, updatable

SGScript.spec.scripts[index].scriptFrom

↩ Parent

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
Description

Workaround for hugo bug not rendering first table row

configMapKeyRef
object
A ConfigMap reference that contains the SQL script to execute. This field is mutually exclusive with secretKeyRef field.

Constraints: optional, updatable
secretKeyRef
object
A Kubernetes SecretKeySelector that contains the SQL script to execute. This field is mutually exclusive with configMapKeyRef field.

Constraints: optional, updatable
SGScript.spec.scripts[index].scriptFrom.configMapKeyRef

↩ Parent

A ConfigMap reference that contains the SQL script to execute. This field is mutually exclusive with secretKeyRef field.

Property
Description

Workaround for hugo bug not rendering first table row

key
string
The key name within the ConfigMap that contains the SQL script to execute.

Constraints: optional, updatable
name
string
The name of the ConfigMap that contains the SQL script to execute.

Constraints: optional, updatable
SGScript.spec.scripts[index].scriptFrom.secretKeyRef

↩ Parent

A Kubernetes SecretKeySelector that contains the SQL script to execute. This field is mutually exclusive with configMapKeyRef field.

Property
Description

Workaround for hugo bug not rendering first table row

key
string
The key of the secret to select from. Must be a valid secret key.

Constraints: optional, updatable
name
string
Name of the referent. More information.

Constraints: optional, updatable

SGScript.status

↩ Parent

Property
Description

Workaround for hugo bug not rendering first table row

scripts
[]object
A list of script entry statuses where a script entry under .spec.scripts is identified by the id field.

Constraints: optional, updatable

SGScript.status.scripts[index]

↩ Parent

Property
Description

Workaround for hugo bug not rendering first table row

hash
string
The hash of a ConfigMap or Secret referenced with the associated script entry.

Constraints: optional, updatable
id
integer
The id that identifies a script entry.

Constraints: optional, updatable