Skip to content

Commit

Permalink
avniproject/avni-product#1406 | Do not hardcode postgres password in …
Browse files Browse the repository at this point in the history
…the Makefile. Use make: Nothing to be done for `../..'. instead
  • Loading branch information
vinayvenu committed Sep 27, 2023
1 parent 5e49ae5 commit 91f5f9c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ define _deploy_schema
flyway -validateOnMigrate=false -user=openchs -password=password -url=jdbc:postgresql://localhost:5432/$1 -schemas=public -locations=filesystem:./avni-server-api/src/main/resources/db/migration/ -table=schema_version migrate
endef

su:=$(shell id -un)
SU ?= $(shell id -un)
su:=$(SU)
DB=openchs
dbServer=localhost
dbPort=5432
Expand All @@ -43,20 +44,20 @@ _drop_roles:
-psql -h $(dbServer) -p $(dbPort) -U $(su) -d postgres -c 'drop role organisation_user';

_clean_db:
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d postgres -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$(database)' AND pid <> pg_backend_pid()"
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d postgres -c 'drop database $(database)';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$(database)' AND pid <> pg_backend_pid()"
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'drop database $(database)';

_build_db:
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d postgres -c "create user openchs with password 'password' createrole";
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d postgres -c 'create database $(database) with owner openchs';
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d $(database) -c 'create extension if not exists "uuid-ossp"';
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d $(database) -c 'create extension if not exists "ltree"';
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d $(database) -c 'create extension if not exists "hstore"';
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d postgres -c 'create role demo with NOINHERIT NOLOGIN';
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d postgres -c 'grant demo to openchs';
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d postgres -c 'create role openchs_impl';
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d postgres -c 'grant openchs_impl to openchs';
-PGPASSWORD=postgres psql -h $(dbServer) -p $(dbPort) -U postgres -d postgres -c 'create role organisation_user createrole admin openchs_impl';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c "create user openchs with password 'password' createrole";
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'create database $(database) with owner openchs';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d $(database) -c 'create extension if not exists "uuid-ossp"';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d $(database) -c 'create extension if not exists "ltree"';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d $(database) -c 'create extension if not exists "hstore"';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'create role demo with NOINHERIT NOLOGIN';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'grant demo to openchs';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'create role openchs_impl';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'grant openchs_impl to openchs';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'create role organisation_user createrole admin openchs_impl';
# </postgres>

# <db>
Expand Down

0 comments on commit 91f5f9c

Please sign in to comment.