Skip to content

Commit

Permalink
Fix issue in ci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
subhashb committed Aug 10, 2024
1 parent 5247de6 commit b6b6dd8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tests/create_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ DB_NAME="test_postgres"
DB_USER="test_postgres"
DB_USER_PASSWORD="test_postgres"

# SQL commands to create the user and database
SQL_CREATE_DB=$(cat <<EOF
# SQL commands to create the user
SQL_CREATE_USER=$(cat <<EOF
CREATE USER $DB_USER WITH PASSWORD '$DB_USER_PASSWORD';
EOF
)

# SQL commands to create the database
SQL_CREATE_DB=$(cat <<EOF
CREATE DATABASE $DB_NAME;
GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;
EOF
Expand All @@ -28,8 +33,11 @@ GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO $DB_USER;
EOF
)

# Execute the SQL commands to create the user and database
# Execute the SQL command to create the user
PGPASSWORD="$DB_ADMIN_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_ADMIN" -d postgres -c "$SQL_CREATE_USER"

# Execute the SQL command to create the database (this must be done separately to avoid transaction block errors)
PGPASSWORD="$DB_ADMIN_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_ADMIN" -d postgres -c "$SQL_CREATE_DB"

# Execute the SQL commands to grant schema-level privileges by connecting to the newly created database
PGPASSWORD="$DB_ADMIN_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_ADMIN" -d "$DB_NAME" -c "$SQL_GRANT_PRIVILEGES"
PGPASSWORD="$DB_ADMIN_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_ADMIN" -d "$DB_NAME" -c "$SQL_GRANT_PRIVILEGES"

0 comments on commit b6b6dd8

Please sign in to comment.