Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- -------------------------------------------------------------------------------------------------
-- Database Name: mosip_resident
-- Database Name: :mosipdbname
-- Release Version : 1.2.1
-- Purpose : Database scripts for Resident Service DB.
-- Create By : Manoj SP
Expand All @@ -10,7 +10,7 @@
-- April-2022 Manoj SP Added otp_transaction table creation scripts with comments.
-- April-2022 Kamesh Shekhar Prasad Added resident_transaction table creation scripts with comments.
-----------------------------------------------------------------------------------------------------
\c mosip_resident
\c :mosipdbname

DROP TABLE IF EXISTS resident.otp_transaction;
DROP TABLE IF EXISTS resident.resident_transaction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
CREATE DATABASE mosip_resident
CREATE DATABASE :mosipdbname
ENCODING = 'UTF8'
LC_COLLATE = 'en_US.UTF-8'
LC_CTYPE = 'en_US.UTF-8'
TABLESPACE = pg_default
OWNER = postgres
TEMPLATE = template0;

COMMENT ON DATABASE mosip_resident IS 'Resident service database stores all the data related to transactions done in resident services';
COMMENT ON DATABASE :mosipdbname IS 'Resident service database stores all the data related to transactions done in resident services';

\c mosip_resident
\c :mosipdbname

DROP SCHEMA IF EXISTS resident CASCADE;
CREATE SCHEMA resident;
ALTER SCHEMA resident OWNER TO postgres;
ALTER DATABASE mosip_resident SET search_path TO resident,pg_catalog,public;
ALTER DATABASE :mosipdbname SET search_path TO resident,pg_catalog,public;

CREATE ROLE residentuser WITH
CREATE ROLE :dbuname WITH
INHERIT
LOGIN
PASSWORD 'dbuserpwd';

GRANT CONNECT
ON DATABASE mosip_resident
TO residentuser;
ON DATABASE :mosipdbname
TO :dbuname;

GRANT USAGE
ON SCHEMA resident
TO residentuser;
TO :dbuname;

GRANT SELECT,INSERT,UPDATE,DELETE,REFERENCES
ON ALL TABLES IN SCHEMA resident
TO residentuser;
TO :dbuname;

-- This Table is used to save the OTP for the user whenever user requests for one using the email id / phone number to log into the application.
CREATE TABLE resident.otp_transaction(
Expand Down Expand Up @@ -69,7 +69,7 @@ COMMENT ON COLUMN resident.otp_transaction.del_dtimes IS 'Date and Timestamp whe
-----------------------------------------------------------------------------------------------------
GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE
ON resident.otp_transaction
TO residentuser;
TO :dbuname;

-- This Table is used to save the resident_grievance_ticket table values.
CREATE TABLE resident.resident_grievance_ticket(
Expand Down Expand Up @@ -111,7 +111,7 @@ COMMENT ON COLUMN resident.resident_grievance_ticket.del_dtimes IS 'Deleted time
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE
ON resident.resident_grievance_ticket
TO residentuser;
TO :dbuname;

-- This Table is used to save the user actions for the user actions table.

Expand All @@ -135,7 +135,7 @@ COMMENT ON COLUMN resident.resident_session.machine_type IS 'The OS of device us

GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE
ON resident.resident_session
TO residentuser;
TO :dbuname;

-- This Table is used to save the transaction related to residents.
CREATE TABLE resident.resident_transaction(
Expand Down Expand Up @@ -215,7 +215,7 @@ COMMENT ON COLUMN resident.resident_transaction.credential_request_id IS 'The cr
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE
ON resident.resident_transaction
TO residentuser;
TO :dbuname;

-- This Table is used to save the user actions for the user actions table.

Expand All @@ -231,4 +231,4 @@ COMMENT ON COLUMN resident.resident_user_actions.last_bell_notif_click_dtimes IS

GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE
ON resident.resident_user_actions
TO residentuser;
TO :dbuname;
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
\c mosip_resident
\c :mosipdbname

REVOKE SELECT, INSERT, REFERENCES, UPDATE, DELETE
ON resident.otp_transaction
TO residentuser;
TO :dbuname;

REVOKE SELECT, INSERT, REFERENCES, UPDATE, DELETE
ON resident.resident_grievance_ticket
TO residentuser;
TO :dbuname;

ALTER TABLE resident.resident_session alter column machine_type type varchar(30);

DROP INDEX IF EXISTS idx_resident_user_actions_ida_token;

REVOKE SELECT, INSERT, REFERENCES, UPDATE, DELETE
ON resident.resident_user_actions
TO residentuser;
TO :dbuname;
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
\c mosip_resident
\c :mosipdbname

GRANT SELECT, INSERT, REFERENCES, UPDATE, DELETE
ON resident.otp_transaction
TO residentuser;
TO :dbuname;

GRANT SELECT, INSERT, REFERENCES, UPDATE, DELETE
ON resident.resident_grievance_ticket
TO residentuser;
TO :dbuname;

ALTER TABLE resident.resident_session alter column machine_type type varchar(100);
-- Adding index to ida_token column
CREATE INDEX idx_resident_user_actions_ida_token ON resident.resident_user_actions (ida_token);
GRANT SELECT, INSERT, REFERENCES, UPDATE, DELETE
ON resident.resident_user_actions
TO residentuser;
TO :dbuname;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Below script is required to rollback from 1.3.0 to 1.3.0-beta.1

\c mosip_resident
\c :mosipdbname

DROP INDEX IF EXISTS resident.idx_resident_transaction_aid_crdtime_desc;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Below script is required to upgrade from 1.3.0-beta.1 to 1.3.0

\c mosip_resident
\c :mosipdbname

CREATE INDEX idx_resident_transaction_aid_crdtime_desc
ON resident.resident_transaction (aid, cr_dtimes DESC);
1 change: 1 addition & 0 deletions db_upgrade_scripts/mosip_resident/upgrade.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MOSIP_DB_NAME=
ACTION=upgrade
MOSIP_DB_NAME=mosip_resident
DB_UNAME=residentuser
DB_SERVERIP=
DB_PORT=
SU_USER=postgres
Expand Down
6 changes: 3 additions & 3 deletions db_upgrade_scripts/mosip_resident/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ echo "Action: "$ACTION

# Terminate existing connections
echo "Terminating active connections"
CONN=$(PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -t -c "SELECT count(pg_terminate_backend(pg_stat_activity.pid)) FROM pg_stat_activity WHERE datname = '$MOSIP_DB_NAME' AND pid <> pg_backend_pid()";exit;)
CONN=$(PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -t -c "SELECT count(pg_terminate_backend(pg_stat_activity.pid)) FROM pg_stat_activity WHERE datname = '$MOSIP_DB_NAME' AND pid <> pg_backend_pid()";exit;)
echo "Terminated connections"

# Execute upgrade or rollback
Expand All @@ -30,7 +30,7 @@ if [ "$ACTION" == "upgrade" ]; then
UPGRADE_SCRIPT_FILE="sql/${CURRENT_VERSION}_to_${UPGRADE_VERSION}_upgrade.sql"
if [ -f "$UPGRADE_SCRIPT_FILE" ]; then
echo "Executing upgrade script $UPGRADE_SCRIPT_FILE"
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 $UPGRADE_SCRIPT_FILE
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f $UPGRADE_SCRIPT_FILE
else
echo "Upgrade script not found, exiting."
exit 1
Expand All @@ -40,7 +40,7 @@ elif [ $ACTION == "rollback" ]; then
REVOKE_SCRIPT_FILE="sql/${CURRENT_VERSION}_to_${UPGRADE_VERSION}_rollback.sql"
if [ -f "$REVOKE_SCRIPT_FILE" ]; then
echo "Executing rollback script $REVOKE_SCRIPT_FILE"
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 $REVOKE_SCRIPT_FILE
PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f $REVOKE_SCRIPT_FILE
else
echo "rollback script not found, exiting."
exit 1
Expand Down
Loading