Skip to content

Commit

Permalink
fix: make init-script.sh idempotent #1173
Browse files Browse the repository at this point in the history
Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
  • Loading branch information
yshyn-iohk committed Jun 17, 2024
1 parent b8869c8 commit 07247d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
6 changes: 2 additions & 4 deletions examples/st-oid4vci/demo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import json
import jwt
import requests
import time
import urllib

import jwt
import requests
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import serialization


MOCKSERVER_URL = "http://localhost:7777"
LOGIN_REDIRECT_URL = "http://localhost:7777/cb"
Expand Down
37 changes: 32 additions & 5 deletions infrastructure/shared/postgres/init-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,39 @@ set -u
function create_user_and_database() {
local database=$1
local app_user=${database}-application-user
echo " Creating user and database '$database'"
echo "Creating user and database '$database'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER "$app_user" WITH PASSWORD 'password';
CREATE DATABASE $database;
\c $database
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO "$app_user";
DO \$\$
BEGIN
IF NOT EXISTS (
SELECT FROM pg_catalog.pg_roles
WHERE rolname = '$app_user') THEN
CREATE USER "$app_user" WITH PASSWORD 'password';
END IF;
END
\$\$;
DO \$\$
BEGIN
IF NOT EXISTS (
SELECT FROM pg_database
WHERE datname = '$database') THEN
CREATE DATABASE $database;
END IF;
END
\$\$;
\c $database
DO \$\$
BEGIN
IF NOT EXISTS (
SELECT FROM pg_catalog.pg_roles
WHERE rolname = '$app_user') THEN
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO "$app_user";
END IF;
END
\$\$;
EOSQL
}

Expand Down

0 comments on commit 07247d1

Please sign in to comment.