Skip to content

Commit e112088

Browse files
jmgilmankukkok3
andauthored
fix: cleans up eventdb entrypoint and adds fix for RDS | NPG-000 (#690)
This PR addresses the following issues: 1. We no longer have a dependency on graphql, so it removes all init code related to that in the eventdb entrypoint 1. The entrypoint was trying to connect to a database that didn't exist a. It was changed to connect to the "root" database on initialization (a new input was added for this) 1. For initialization to work with RDS, the root role must be assigned the role the database is being created with a. This is a weird RDS requirement where the root role isn't really "super" 1. The debug print statements in the init script were printing out the raw database password every single run a. Even though our logs are private, this is still a serious issue b. The debug statements were moved to the entrypoint instead so they could be conditionally controlled 1. The ideascale SQL for the dev environment had a syntax error in it --------- Co-authored-by: kukkok3 <[email protected]>
1 parent 543779c commit e112088

File tree

4 files changed

+34
-43
lines changed

4 files changed

+34
-43
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ jobs:
226226
uses: taiki-e/install-action@nextest
227227

228228
- name: Install cargo-make
229-
run: cargo install --force cargo-make --locked
229+
run: cargo install --force cargo-make --version 0.37.10 --locked
230230

231231
- name: Install refinery
232232
run: cargo install refinery_cli --version 0.8.7 --locked

containers/event-db-migrations/entry.sh

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,16 @@
1313
# DB_HOST - The hostname of the database server
1414
# DB_PORT - The port of the database server
1515
# DB_NAME - The name of the database
16+
# DB_ROOT_NAME - The name of the root database (usually postgres)
1617
# DB_SUPERUSER - The username of the database superuser
1718
# DB_SUPERUSER_PASSWORD - The password of the database superuser
1819
# DB_USER - The username of the database user
1920
# DB_USER_PASSWORD - The password of the database user
2021
# DB_SKIP_HISTORICAL_DATA - If set, historical data will not be added to the database (optional)
2122
# DB_SKIP_TEST_DATA - If set, test data will not be added to the database (optional)
2223
# DB_SKIP_STAGE_DATA - If set, stage specific data will not be added to the database (optional)
23-
# ADMIN_ROLE_PASSWORD - The password of the cat_admin role for graphql
24-
# ADMIN_USER_PASSWORD - The password of the admin user for graphql
25-
# ANON_ROLE_PASSWORD - The password of the cat_anon role for graphql
26-
# ADMIN_FIRST_NAME - The first name of the admin user for graphql (optional)
27-
# ADMIN_LAST_NAME - The last name of the admin user for graphql (optional)
28-
# ADMIN_ABOUT - The about of the admin user for graphql (optional)
29-
# ADMIN_EMAIL - The email of the admin user for graphql (optional)
3024
# REINIT_EVENT_DB - If set, the database will be reinitialized (optional) (DESTRUCTIVE)
3125
# SKIP_EVENT_DB_INIT - If set, the event database will not be initialized (optional)
32-
# SKIP_GRAPHQL_INIT - If set, graphql will not be initialized (optional)
3326
# DEBUG - If set, the script will print debug information (optional)
3427
# DEBUG_SLEEP - If set, the script will sleep for the specified number of seconds (optional)
3528
# STAGE - The stage being run. Currently only controls if stage specific data is applied to the DB (optional)
@@ -71,34 +64,41 @@ REQUIRED_ENV=(
7164
"DB_HOST"
7265
"DB_PORT"
7366
"DB_NAME"
67+
"DB_ROOT_NAME"
7468
"DB_SUPERUSER"
7569
"DB_SUPERUSER_PASSWORD"
7670
"DB_USER"
7771
"DB_USER_PASSWORD"
78-
"ADMIN_ROLE_PASSWORD"
79-
"ADMIN_USER_PASSWORD"
80-
"ANON_ROLE_PASSWORD"
8172
)
8273
check_env_vars "${REQUIRED_ENV[@]}"
8374

8475
# Export environment variables
8576
export PGHOST="${DB_HOST}"
8677
export PGPORT="${DB_PORT}"
87-
export PGUSER="${DB_SUPERUSER}"
88-
export PGPASSWORD="${DB_SUPERUSER_PASSWORD}"
89-
export PGDATABASE="${DB_NAME}"
90-
91-
: "${ADMIN_FIRST_NAME:='Admin'}"
92-
: "${ADMIN_LAST_NAME:='Default'}"
93-
: "${ADMIN_ABOUT:='Default Admin User'}"
94-
: "${ADMIN_EMAIL:='[email protected]'}"
9578

9679
# Sleep if DEBUG_SLEEP is set
9780
debug_sleep
9881

82+
if [ -n "${DEBUG:-}" ]; then
83+
echo ">>> Environment variables:"
84+
echo "DB_HOST: ${DB_HOST}"
85+
echo "DB_PORT: ${DB_PORT}"
86+
echo "DB_NAME: ${DB_NAME}"
87+
echo "DB_ROOT_NAME: ${DB_ROOT_NAME}"
88+
echo "DB_SUPERUSER: ${DB_SUPERUSER}"
89+
echo "DB_SUPERUSER_PASSWORD: ${DB_SUPERUSER_PASSWORD}"
90+
echo "DB_USER: ${DB_USER}"
91+
echo "DB_USER_PASSWORD: ${DB_USER_PASSWORD}"
92+
fi
93+
9994
# Initialize database if necessary
10095
if [[ ! -f ./tmp/initialized || -n "${REINIT_EVENT_DB:-}" ]]; then
10196

97+
# Connect using the superuser to create the event database
98+
export PGUSER="${DB_SUPERUSER}"
99+
export PGPASSWORD="${DB_SUPERUSER_PASSWORD}"
100+
export PGDATABASE="${DB_ROOT_NAME}"
101+
102102
PSQL_FLAGS=""
103103
if [ -n "${DEBUG:-}" ]; then
104104
PSQL_FLAGS="-e"
@@ -110,21 +110,8 @@ if [[ ! -f ./tmp/initialized || -n "${REINIT_EVENT_DB:-}" ]]; then
110110
-v dbName="${DB_NAME}" \
111111
-v dbDescription="Catalayst Event DB" \
112112
-v dbUser="${DB_USER}" \
113-
-v dbUserPw="${DB_USER_PASSWORD}"
114-
fi
115-
116-
if [[ -z "${SKIP_GRAPHQL_INIT:-}" ]]; then
117-
echo ">>> Initializing graphql..."
118-
psql "${PSQL_FLAGS}" -f ./setup/graphql-setup.sql \
119-
-v dbName="${DB_NAME}" \
120-
-v dbUser="${DB_USER}" \
121-
-v adminUserFirstName="${ADMIN_FIRST_NAME}" \
122-
-v adminUserLastName="${ADMIN_LAST_NAME}" \
123-
-v adminUserAbout="${ADMIN_ABOUT}" \
124-
-v adminUserEmail="${ADMIN_EMAIL}" \
125-
-v adminRolePw="${ADMIN_ROLE_PASSWORD}" \
126-
-v adminUserPw="${ADMIN_USER_PASSWORD}" \
127-
-v anonRolePw="${ANON_ROLE_PASSWORD}"
113+
-v dbUserPw="${DB_USER_PASSWORD}" \
114+
-v dbRootUser="${DB_SUPERUSER}"
128115
fi
129116

130117
if [[ ! -f ./tmp/initialized ]]; then
@@ -135,6 +122,10 @@ else
135122
fi
136123

137124
# Run migrations
125+
export PGUSER="${DB_USER}"
126+
export PGPASSWORD="${DB_USER_PASSWORD}"
127+
export PGDATABASE="${DB_NAME}"
128+
138129
echo ">>> Running migrations..."
139130
export DATABASE_URL="postgres://${DB_USER}:${DB_USER_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}"
140131
./refinery migrate -e DATABASE_URL -c ./refinery.toml -p ./migrations

src/event-db/setup/setup-db.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@
2929
\set dbUserPw `echo ${DB_USER_PW:-CHANGE_ME}`
3030
\endif
3131

32-
-- DISPLAY ALL VARIABLES
33-
\echo VARIABLES:
34-
\echo -> dbName ................. = :dbName
35-
\echo -> dbDescription .......... = :dbDescription
36-
\echo -> dbUser ................. = :dbUser
37-
\echo -> dbUserPw / $DB_USER_PW . = :dbUserPw
38-
32+
-- The root db user of the database instance (usually postgres).
33+
\if :{?dbRootUser} \else
34+
\set dbRootUser 'postgres'
35+
\endif
3936

4037
-- Cleanup if we already ran this before.
4138
DROP DATABASE IF EXISTS :"dbName";
@@ -50,6 +47,9 @@ ALTER DEFAULT privileges REVOKE EXECUTE ON functions FROM public;
5047

5148
ALTER DEFAULT privileges IN SCHEMA public REVOKE EXECUTE ON functions FROM :"dbUser";
5249

50+
-- This is necessary for RDS to work.
51+
GRANT :"dbUser" TO :"dbRootUser";
52+
5353
-- Create the database.
5454
CREATE DATABASE :"dbName" WITH OWNER :"dbUser";
5555

src/event-db/stage_data/dev/00002_fund100_params.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- Define F100 IdeaScale parameters.
22
INSERT INTO config (id, id2, id3, value) VALUES (
3-
'ideascale,
3+
'ideascale',
44
'100',
55
'',
66
'{

0 commit comments

Comments
 (0)