blob: 217ce3738e857b4abd41552e9ff2ff5292974032 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nuvolaris-postgres-conf
namespace: nuvolaris
data:
# This bash script is run once, the 1st time a Primary PostgreSql container is created. It is run in the Primary container only.
#
# You can edit this script as it suits your requirement. For example, you could add SQL statements to create specific
# database(s), user(s), grant accesses, etc...
# See the commented examples in the script below.
#
# This script will be located in the container folder "/docker-entrypoint-initdb.d"
# That folder is referenced in the Postgres Docker page: https://hub.docker.com/_/postgres
#
# If you edit the script in this file, your changes will apply to all Kubegres resources.
# Alternatively, you can override it for your Kubegres resource. To do so, create a custom configMap and in your
# Kubegres resource file set its name in 'spec.customConfig'. In your ConfigFile, copy the contents of this script
# and edit it as its suits your requirement.
#
primary_init_script.sh: |
#!/bin/bash
set -e
# This script assumes that the env-var $POSTGRES_NUVOLARIS_DB_PASSWORD contains the password of the custom user to create.
# You can add any env-var in your Kubegres resource config YAML.
dt=$(date '+%d/%m/%Y %H:%M:%S');
echo "$dt - Running init script the 1st time Primary PostgreSql container is created...";
echo "$dt - Running: psql -v ON_ERROR_STOP=1 --username $POSTGRES_USER --dbname $POSTGRES_DB ...";
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE nuvolaris;
CREATE USER nuvolaris WITH PASSWORD '$POSTGRES_NUVOLARIS_DB_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE "nuvolaris" to nuvolaris;
EOSQL
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname nuvolaris <<-EOSQL
CREATE EXTENSION IF NOT EXISTS vector;
EOSQL
echo "$dt - Init script is completed";