Skip to content

Commit b210029

Browse files
committed
fix: missing bits
1 parent 9f999fe commit b210029

File tree

4 files changed

+61
-31
lines changed

4 files changed

+61
-31
lines changed

apps/database/mig_data.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
echo "Seeding the database..."
3+
4+
export DATABASE_DIR=${DATABASE_DIR:-..}
5+
6+
#retry() {
7+
# max_attempts="$1"
8+
# shift
9+
# seconds="$1"
10+
# shift
11+
# cmd="$@"
12+
# attempt_num=1
13+
#
14+
# until $cmd; do
15+
# if [ $attempt_num -eq $max_attempts ]; then
16+
# echo "Attempt $attempt_num failed and there are no more attempts left!"
17+
# return 1
18+
# else
19+
# echo "Attempt $attempt_num failed! Trying again in $seconds seconds..."
20+
# attempt_num=$(expr "$attempt_num" + 1)
21+
# sleep "$seconds"
22+
# fi
23+
# done
24+
#}
25+
#retry 10 1 psql $DATABASE_URL --dbname=$DBNAME -c '\l' >/dev/null
26+
27+
echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is up - executing command"
28+
29+
for i in ./test_data/*.sql; do # Whitespace-safe but not recursive.
30+
echo "$i"
31+
yarn graphile-migrate run $i
32+
done
Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,12 @@
11
BEGIN;
2-
3-
DO
4-
$$
5-
BEGIN
6-
CREATE USER :DATABASE_AUTHENTICATOR WITH PASSWORD ':DATABASE_AUTHENTICATOR_PASSWORD';
7-
EXCEPTION
8-
WHEN DUPLICATE_OBJECT THEN
9-
RAISE NOTICE 'not creating authenticator role -- it already exists';
10-
END
11-
$$;
12-
13-
14-
DO
15-
$$
16-
BEGIN
17-
CREATE ROLE :DATABASE_VISITOR;
18-
EXCEPTION
19-
WHEN DUPLICATE_OBJECT THEN
20-
RAISE NOTICE 'not creating viewer role -- it already exists';
21-
END
22-
$$;
23-
242
GRANT CONNECT ON DATABASE :DATABASE_NAME TO :DATABASE_OWNER;
253
GRANT CONNECT ON DATABASE :DATABASE_NAME TO :DATABASE_AUTHENTICATOR;
264
GRANT ALL ON DATABASE :DATABASE_NAME TO :DATABASE_OWNER;
27-
ALTER SCHEMA public OWNER TO :DATABASE_OWNER;
5+
-- ALTER SCHEMA public OWNER TO :DATABASE_OWNER;
286

297
-- Some extensions require superuser privileges, so we create them before migration time.
30-
-- CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
31-
-- CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
328
CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public;
339
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
3410
CREATE EXTENSION IF NOT EXISTS unaccent WITH SCHEMA public;
35-
CREATE EXTENSION IF NOT EXISTS "pg_trgm" WITH SCHEMA public;
36-
11+
CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;
3712
COMMIT;

apps/database/test_data/00-users.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Manually create the test user so JWT works across database resets
2+
INSERT INTO app_public.user (id, username, name, is_verified)
3+
VALUES ('da221b05-a99c-485d-a278-015e7baaeda2', 'testuser1', 'Test User', TRUE);
4+
UPDATE app_private.user_secrets us
5+
SET password_hash = crypt('test123', gen_salt('bf'))
6+
WHERE user_id = 'da221b05-a99c-485d-a278-015e7baaeda2';
7+
8+
INSERT INTO app_public.user (id, username, name, is_verified)
9+
VALUES ('23e675b1-d581-4d84-96a9-8f73dbee72ad', 'ncrmro', 'Nicholas Romero', TRUE);
10+
UPDATE app_private.user_secrets us
11+
SET password_hash = crypt('test123', gen_salt('bf'))
12+
WHERE user_id = '23e675b1-d581-4d84-96a9-8f73dbee72ad';
13+
14+
SELECT *
15+
FROM app_public.register_user(
16+
username := 'testuser2', password := 'test123'
17+
);
18+
19+
SELECT *
20+
FROM app_public.register_user(
21+
username := 'nopartorsystemuser', password := 'test123'
22+
);
23+
24+
SELECT *
25+
FROM app_public.register_user(
26+
username := 'noemailuser', password := 'test123'
27+
);

docker-compose.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ version: "3.7"
33
services:
44
db:
55
image: postgres:13.1-alpine
6-
environment:
7-
POSTGRES_USER: $DATABASE_OWNER
8-
POSTGRES_PASSWORD: $DATABASE_OWNER_PASSWORD
9-
POSTGRES_DB: $DATABASE_NAME
106
env_file:
117
- .env
128
volumes:

0 commit comments

Comments
 (0)