fp/scripts/postgres-create.sh

104 lines
3.9 KiB
Bash
Raw Normal View History

2024-06-12 04:28:36 +00:00
#!/bin/sh
2024-07-04 21:20:29 +00:00
# bindir=$(dirname "$(readlink -fm "$0")")
# source "${bindir}/../.env"
2024-07-30 20:34:25 +00:00
2024-07-23 02:59:41 +00:00
postgres_pod_name=postgresql-primary-0
2024-06-12 04:28:36 +00:00
2024-07-18 12:37:36 +00:00
if [ -z $POSTGRES_PASSWORD ]; then
2024-07-30 20:34:25 +00:00
echo "POSTGRES_PASSWORD was missing in env. Are you executing this script via Tilt? (that is the intended method)"
2024-06-12 04:28:36 +00:00
exit 5
fi
2024-08-07 01:13:58 +00:00
# ## Enable pgcrypto (needed by pg-boss)
# kubectl -n futureporn exec ${postgres_pod_name} -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "\
# CREATE EXTENSION pgcrypto;"
2024-07-28 00:42:09 +00:00
2024-08-07 01:13:58 +00:00
# ## Create the temporal databases
# kubectl -n futureporn exec ${postgres_pod_name} -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "\
# CREATE DATABASE temporal_visibility \
# WITH \
# OWNER = postgres \
# ENCODING = 'UTF8' \
# LOCALE_PROVIDER = 'libc' \
# CONNECTION LIMIT = -1 \
# IS_TEMPLATE = False;"
2024-06-12 04:28:36 +00:00
2024-08-07 01:13:58 +00:00
# kubectl -n futureporn exec ${postgres_pod_name} -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "\
# CREATE DATABASE temporal \
# WITH \
# OWNER = postgres \
# ENCODING = 'UTF8' \
# LOCALE_PROVIDER = 'libc' \
# CONNECTION LIMIT = -1 \
# IS_TEMPLATE = False;"
2024-06-12 04:28:36 +00:00
2024-07-23 02:59:41 +00:00
2024-07-10 02:34:23 +00:00
2024-06-12 04:28:36 +00:00
# ./temporal-sql-tool -u $(SQL_USER) --pw $(SQL_PASSWORD) -p 5432 --pl postgres12 --db $(TEMPORAL_DB) drop -f
# ./temporal-sql-tool -u $(SQL_USER) --pw $(SQL_PASSWORD) -p 5432 --pl postgres12 --db $(TEMPORAL_DB) create
# ./temporal-sql-tool -u $(SQL_USER) --pw $(SQL_PASSWORD) -p 5432 --pl postgres12 --db $(TEMPORAL_DB) setup -v 0.0
# ./temporal-sql-tool -u $(SQL_USER) --pw $(SQL_PASSWORD) -p 5432 --pl postgres12 --db $(TEMPORAL_DB) update-schema -d ./schema/postgresql/v12/temporal/versioned
# ./temporal-sql-tool -u $(SQL_USER) --pw $(SQL_PASSWORD) -p 5432 --pl postgres12 --db $(VISIBILITY_DB) drop -f
# ./temporal-sql-tool -u $(SQL_USER) --pw $(SQL_PASSWORD) -p 5432 --pl postgres12 --db $(VISIBILITY_DB) create
# ./temporal-sql-tool -u $(SQL_USER) --pw $(SQL_PASSWORD) -p 5432 --pl postgres12 --db $(VISIBILITY_DB) setup-schema -v 0.0
# ./temporal-sql-tool -u $(SQL_USER) --pw $(SQL_PASSWORD) -p 5432 --pl postgres12 --db $(VISIBILITY_DB) update-schema -d ./schema/postgresql/v12/visibility/versioned
## Create the futureporn Strapi database
2024-07-23 02:59:41 +00:00
kubectl -n futureporn exec ${postgres_pod_name} -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "\
2024-06-12 04:28:36 +00:00
CREATE DATABASE futureporn_db \
WITH \
OWNER = postgres \
ENCODING = 'UTF8' \
LOCALE_PROVIDER = 'libc' \
CONNECTION LIMIT = -1 \
IS_TEMPLATE = False;"
2024-07-28 00:42:09 +00:00
2024-08-07 01:13:58 +00:00
# @futureporn/migrations takes care of these tasks now
# ## Create graphile_worker db (for backend tasks)
# kubectl -n futureporn exec ${postgres_pod_name} -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "\
# CREATE DATABASE graphile_worker \
# WITH \
# OWNER = postgres \
# ENCODING = 'UTF8' \
# LOCALE_PROVIDER = 'libc' \
# CONNECTION LIMIT = -1 \
# IS_TEMPLATE = False;"
# ## create futureporn user
# kubectl -n futureporn exec ${postgres_pod_name} -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "\
# CREATE ROLE futureporn \
# WITH \
# LOGIN \
# NOSUPERUSER \
# NOCREATEDB \
# NOCREATEROLE \
# INHERIT \
# NOREPLICATION \
# NOBYPASSRLS \
# CONNECTION LIMIT -1 \
# PASSWORD '$POSTGRES_REALTIME_PASSWORD';"
2024-06-12 04:28:36 +00:00
## grant futureporn user all privs
2024-08-07 01:13:58 +00:00
# kubectl -n futureporn exec ${postgres_pod_name} -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "\
# GRANT ALL PRIVILEGES ON DATABASE postgrest TO futureporn;"
# kubectl -n futureporn exec ${postgres_pod_name} -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "\
# GRANT ALL PRIVILEGES ON DATABASE graphile_worker TO futureporn;"
2024-06-12 04:28:36 +00:00
## import schema
## I have a file, schema.psql that I want to import. How do I do that?
2024-07-30 20:34:25 +00:00
# kubectl -n futureporn exec postgresql -- psql -U postgres --command "\ ;"
# kubectl -n futureporn exec postgresql -- psql -U postgres -f - < "${bindir}/postgres-2024-05-09-futureporn_db-schema-only.psql"
2024-06-12 04:28:36 +00:00