Enable execution of scripts for a cluster
Problem to solve
When starting up a StackGres cluster this comes empty without user created content.
Further details
Usually a database is created alongside with users, schemas, tables and other objects (functions, triggers, etc.). SQL commands to create all those objects in the cluster are contained in one or more SQL scripts that are executed in a predefined order.
Proposal
Modify cluster CR in order to allow to specify a sequence of scripts to be executed:
apiVersion: stackgres.io/v1beta1
kind: SGCluster
metadata:
name: example-of-cluster-with-scripts
spec:
initData:
scripts:
- name: create-user
database: postgres # default
valueFrom:
secretKeyRef:
name: example-user
key: script
- name: create-database
value: |
CREATE DATABASE example WITH OWNER example;
- name: create-schema
database: example
valueFrom:
configMapKeyRef:
name: example-schema
key: script
Scripts will be executed following the specified order. Key value
and valueFrom
are mutually exclusive. Script will be executed only when database bootstrap for the first time on the specified database with user postgres
. The user will be responsible if SQL commands will affect the functionality of the cluster.