2024-11-13 13:52:17 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2024-11-14 12:01:06 +00:00
|
|
|
# shellcheck source=/dev/null
|
2024-11-13 13:52:17 +00:00
|
|
|
. /conf/init-cdn-db.conf
|
|
|
|
|
2024-11-14 12:01:06 +00:00
|
|
|
# Create database named after user, then create a schema named the same as the
|
|
|
|
# user which is also owned by that user. Because search_path (SHOW
|
|
|
|
# search_path;) starts with "$user" by default this means any tables will be
|
|
|
|
# created in that user-specific SCHEMA by default instead of falling back to
|
|
|
|
# "public". This follows the "secure schema usage pattern" summarized as
|
|
|
|
# "Constrain ordinary users to user-private schemas" from
|
|
|
|
# https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATTERNS
|
|
|
|
#
|
|
|
|
# "In PostgreSQL 15 and later, the default configuration supports this usage
|
|
|
|
# pattern. In prior versions, or when using a database that has been upgraded
|
|
|
|
# from a prior version, you will need to remove the public CREATE privilege
|
|
|
|
# from the public schema"
|
2024-11-13 13:52:17 +00:00
|
|
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
2024-11-14 12:01:06 +00:00
|
|
|
CREATE USER cdn WITH PASSWORD '${cdn_password:?}';
|
2024-11-13 13:52:17 +00:00
|
|
|
CREATE DATABASE cdn;
|
|
|
|
GRANT ALL PRIVILEGES ON DATABASE cdn TO cdn;
|
2024-11-14 12:01:06 +00:00
|
|
|
\c cdn;
|
|
|
|
CREATE SCHEMA cdn AUTHORIZATION cdn;
|
2024-11-13 13:52:17 +00:00
|
|
|
EOSQL
|