Skip to content

Commit

Permalink
MOSIP-32075 : DB attributes of PMS are hardcoded in db_scripts (sql s…
Browse files Browse the repository at this point in the history
…cripts)

Signed-off-by: sudeep <[email protected]>
  • Loading branch information
Sudeep7353 committed Jan 8, 2025
1 parent 42d83c3 commit 60b93c8
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 26 deletions.
8 changes: 4 additions & 4 deletions db_scripts/mosip_pms/db.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
CREATE DATABASE mosip_pms
CREATE DATABASE :mosipdbname
ENCODING = 'UTF8'
TABLESPACE = pg_default
OWNER = postgres;

COMMENT ON DATABASE mosip_pms IS 'PMS related entities and its data is stored in this database';
COMMENT ON DATABASE :mosipdbname IS 'PMS related entities and its data is stored in this database';

\c mosip_pms
\c :mosipdbname

DROP SCHEMA IF EXISTS pms CASCADE;
CREATE SCHEMA pms;
ALTER SCHEMA pms OWNER TO postgres;
ALTER DATABASE mosip_pms SET search_path TO pms,pg_catalog,public;
ALTER DATABASE :mosipdbname SET search_path TO pms,pg_catalog,public;
2 changes: 1 addition & 1 deletion db_scripts/mosip_pms/ddl.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\c mosip_pms
\c :mosipdbname

\ir ddl/pms-auth_policy.sql
\ir ddl/pms-auth_policy_h.sql
Expand Down
2 changes: 2 additions & 0 deletions db_scripts/mosip_pms/deploy.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ DB_PORT=5432
SU_USER=postgres
DEFAULT_DB_NAME=postgres
MOSIP_DB_NAME=mosip_pms
DB_UNAME=pmsuser
DML_FLAG=1
DBUSER_PWD=
16 changes: 7 additions & 9 deletions db_scripts/mosip_pms/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

## Properties file
set -e
properties_file="$1"
Expand All @@ -22,25 +21,24 @@ echo "Terminated connections"

## Drop db and role
echo "Dropping DB"
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f drop_db.sql
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f drop_db.sql -v mosipdbname=$MOSIP_DB_NAME
echo "Dropping user"
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f drop_role.sql
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f drop_role.sql -v dbuname=$DB_UNAME

## Create users
echo `date "+%m/%d/%Y %H:%M:%S"` ": Creating database users"
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f role_dbuser.sql -v dbuserpwd=\'$DBUSER_PWD\'
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f role_dbuser.sql -v dbuname=$DB_UNAME -v dbuserpwd=$DBUSER_PWD

## Create DB
echo "Creating DB"
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f db.sql
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f ddl.sql

PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f db.sql -v mosipdbname=$MOSIP_DB_NAME
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f ddl.sql -v mosipdbname=$MOSIP_DB_NAME
## Grants
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f grants.sql
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f grants.sql -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME

## Populate tables
if [ ${DML_FLAG} == 1 ]
then
echo `date "+%m/%d/%Y %H:%M:%S"` ": Deploying DML for ${MOSIP_DB_NAME} database"
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f dml.sql
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f dml.sql -v mosipdbname=$MOSIP_DB_NAME
fi
2 changes: 1 addition & 1 deletion db_scripts/mosip_pms/dml.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\c mosip_pms
\c :mosipdbname

TRUNCATE TABLE pms.partner_type cascade ;
\COPY pms.partner_type (code,partner_description,is_active,cr_by,cr_dtimes,is_policy_required) FROM './dml/pms-partner_type.csv' delimiter ',' HEADER csv;
Expand Down
2 changes: 1 addition & 1 deletion db_scripts/mosip_pms/drop_db.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DROP DATABASE IF EXISTS mosip_pms;
DROP DATABASE IF EXISTS :mosipdbname;

2 changes: 1 addition & 1 deletion db_scripts/mosip_pms/drop_role.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
drop role if exists pmsuser;
drop role if exists :dbuname;
13 changes: 6 additions & 7 deletions db_scripts/mosip_pms/grants.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
\c mosip_pms
\c :mosipdbname

GRANT CONNECT
ON DATABASE mosip_pms
TO pmsuser;
ON DATABASE :mosipdbname
TO :dbuname;

GRANT USAGE
ON SCHEMA pms
TO pmsuser;
TO :dbuname;

GRANT SELECT,INSERT,UPDATE,DELETE,TRUNCATE,REFERENCES
ON ALL TABLES IN SCHEMA pms
TO pmsuser;
TO :dbuname;

ALTER DEFAULT PRIVILEGES IN SCHEMA pms
GRANT SELECT,INSERT,UPDATE,DELETE,REFERENCES ON TABLES TO pmsuser;

GRANT SELECT,INSERT,UPDATE,DELETE,REFERENCES ON TABLES TO :dbuname;
4 changes: 2 additions & 2 deletions db_scripts/mosip_pms/role_dbuser.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE ROLE pmsuser WITH
CREATE ROLE :dbuname WITH
INHERIT
LOGIN
PASSWORD :dbuserpwd;
PASSWORD ':dbuserpwd';

0 comments on commit 60b93c8

Please sign in to comment.