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
Required
Updatable
May Require Restart
Type
Description

Workaround for hugo bug not rendering first table row

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

SGScript.spec

↩ Parent

Property
Required
Updatable
May Require Restart
Type
Description

Workaround for hugo bug not rendering first table row

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.

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
Required
Updatable
May Require Restart
Type
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.
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 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.

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

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 true then wrapInTransaction field must be set.

This is false by default.

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:

  • 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

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
Required
Updatable
May Require Restart
Type
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.
secretKeyRef object A Kubernetes SecretKeySelector that contains the SQL script to execute. This field is mutually exclusive with configMapKeyRef field.
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
Required
Updatable
May Require Restart
Type
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.
name string The name of the ConfigMap that contains the SQL script to execute.
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
Required
Updatable
May Require Restart
Type
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.
name string Name of the referent. More information.

SGScript.status

↩ Parent

Property
Required
Updatable
May Require Restart
Type
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.

SGScript.status.scripts[index]

↩ Parent

Property
Required
Updatable
May Require Restart
Type
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.
id integer The id that identifies a script entry.