diff --git a/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql index 3ed43408f2..2e2d7d69f0 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql @@ -1,4 +1,4 @@ -\c mosip_ida +\c :mosipdbname REASSIGN OWNED BY postgres TO sysadmin; diff --git a/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql index 61344dd487..c76edb500c 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql @@ -1,12 +1,12 @@ -\c mosip_ida +\c :mosipdbname REASSIGN OWNED BY sysadmin TO postgres; -REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA ida FROM idauser; +REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA ida FROM :dbuname; REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA ida FROM sysadmin; -GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ALL TABLES IN SCHEMA ida TO idauser; +GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ALL TABLES IN SCHEMA ida TO :dbuname; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA ida TO postgres; @@ -36,7 +36,7 @@ CREATE TABLE ida.api_key_data ( GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ida.api_key_data - TO idauser; + TO :dbuname; --index section starts---- CREATE INDEX ind_akd_apkeyid ON ida.api_key_data (api_key_id); @@ -62,7 +62,7 @@ CREATE TABLE ida.partner_data ( GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ida.partner_data - TO idauser; + TO :dbuname; --index section starts---- CREATE INDEX ind_pd_pid ON ida.partner_data (partner_id); --index section ends------ @@ -87,7 +87,7 @@ CREATE TABLE ida.partner_mapping ( GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ida.partner_mapping - TO idauser; + TO :dbuname; --index section starts---- CREATE INDEX ind_pm_pid ON ida.partner_mapping (partner_id); --index section ends------ @@ -115,7 +115,7 @@ CREATE TABLE ida.policy_data ( GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ida.policy_data - TO idauser; + TO :dbuname; --index section starts---- CREATE INDEX ind_pl_pid ON ida.policy_data (policy_id); @@ -141,7 +141,7 @@ CREATE TABLE ida.misp_license_data ( GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ida.misp_license_data - TO idauser; + TO :dbuname; --index section starts---- CREATE INDEX ind_mld_lk ON ida.misp_license_data (license_key); --index section ends------ @@ -164,7 +164,7 @@ CREATE TABLE ida.anonymous_profile( GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ida.anonymous_profile - TO idauser; + TO :dbuname; -- ddl-end -- COMMENT ON TABLE ida.anonymous_profile IS 'anonymous_profile: Anonymous profiling information for reporting purpose.'; COMMENT ON COLUMN ida.anonymous_profile.id IS 'Reference ID: System generated id for references in the system.'; diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_rollback.sql index 45325dd4de..f4173f7767 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_rollback.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_rollback.sql @@ -1,4 +1,4 @@ -\c mosip_ida +\c :mosipdbname ALTER TABLE ida.misp_license_data DROP COLUMN policy_id; diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_upgrade.sql index 4d19ecafd4..78ffb541f5 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_upgrade.sql @@ -1,4 +1,4 @@ -\c mosip_ida +\c :mosipdbname ALTER TABLE ida.misp_license_data ADD policy_id character varying(50); @@ -25,7 +25,7 @@ CREATE TABLE ida.oidc_client_data ( GRANT SELECT, INSERT, REFERENCES, UPDATE, DELETE ON ida.oidc_client_data - TO idauser; + TO :dbuname; -- DROP TABLE IF EXISTS ida.kyc_token_store CASCADE; CREATE TABLE ida.kyc_token_store( @@ -49,4 +49,4 @@ CREATE TABLE ida.kyc_token_store( GRANT SELECT, INSERT, REFERENCES, UPDATE, DELETE ON ida.kyc_token_store - TO idauser; \ No newline at end of file + TO :dbuname; \ No newline at end of file diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_rollback.sql index 23b12cc2ac..e5b7f745ea 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_rollback.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_rollback.sql @@ -1,4 +1,4 @@ -\c mosip_ida +\c :mosipdbname ALTER TABLE ida.kyc_token_store DROP COLUMN request_trn_id; diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql index 6cc241fcd2..d15c1b4c06 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql @@ -1,5 +1,5 @@ -- ------------------------------------------------------------------------------------------------- --- Database Name : mosip_ida +-- Database Name : :mosipdbname -- Release Version : 1.2 -- Purpose : Database Alter scripts for the release for ID Authentication DB. -- Create By : Ram Bhatt @@ -8,7 +8,7 @@ -- Modified Date Modified By Comments / Remarks -- ------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- -\c mosip_ida +\c :mosipdbname ALTER TABLE ida.kyc_token_store ADD request_trn_id character varying(64); @@ -33,7 +33,7 @@ CREATE TABLE ida.ident_binding_cert_store ( GRANT SELECT, INSERT, REFERENCES, UPDATE, DELETE ON ida.ident_binding_cert_store - TO idauser; + TO :dbuname; -- ddl-end -- INSERT INTO ida.key_policy_def (app_id, key_validity_duration, is_active, cr_by, cr_dtimes, upd_by, upd_dtimes, is_deleted, del_dtimes, pre_expire_days, access_allowed) diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_upgrade.sql index e19d945e65..064ff19de8 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_upgrade.sql @@ -1,3 +1,3 @@ -\c mosip_ida +\c :mosipdbname DROP TABLE IF EXISTS ida.key_policy_def_h; diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1-B5_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1-B5_upgrade.sql index efb74c3bab..f687d10d7e 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1-B5_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1-B5_upgrade.sql @@ -1,5 +1,5 @@ -- ------------------------------------------------------------------------------------------------- --- Database Name : mosip_ida +-- Database Name : :mosipdbname -- Release Version : 1.2.1 -- Purpose : Database Alter scripts for the release for ID Authentication DB. -- Create By : Mahammed Taheer @@ -8,7 +8,7 @@ -- Modified Date Modified By Comments / Remarks -- ------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- -\c mosip_ida sysadmin +\c :mosipdbname sysadmin CREATE TABLE ida.cred_subject_id_store( id character varying(36) NOT NULL, diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1-B6_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1-B6_upgrade.sql index 1400ca91be..7022506486 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1-B6_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1-B6_upgrade.sql @@ -1,4 +1,4 @@ -\c mosip_ida +\c :mosipdbname ALTER TABLE ida.credential_event_store ALTER COLUMN credential_transaction_id type character varying(64); diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.1.0_to_1.3.0_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.1.0_to_1.3.0_rollback.sql index cc93d7d7d7..c0907d6dbf 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.1.0_to_1.3.0_rollback.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.1.0_to_1.3.0_rollback.sql @@ -11,7 +11,7 @@ TRUNCATE TABLE batch_step_execution_context CASCADE; GRANT usage, SELECT ON ALL SEQUENCES IN SCHEMA ida - TO idauser; + TO :dbuname; -- Revert ALTER on BATCH_STEP_EXECUTION ALTER TABLE BATCH_STEP_EXECUTION DROP COLUMN CREATE_TIME; -- Remove the column added diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.1.1_to_1.2.1.2_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.1.1_to_1.2.1.2_rollback.sql index f441ed98a6..cc4d95feee 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.1.1_to_1.2.1.2_rollback.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.1.1_to_1.2.1.2_rollback.sql @@ -1,3 +1,3 @@ -- Below script required to upgrade from 1.3.0-B2 to 1.3.0 -\c mosip_ida +\c :mosipdbname DROP INDEX IF EXISTS cred_event_store_status_cr_dtimes; \ No newline at end of file diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.1.1_to_1.2.1.2_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.1.1_to_1.2.1.2_upgrade.sql index 6f20488c5f..ceed12a068 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.1.1_to_1.2.1.2_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.1.1_to_1.2.1.2_upgrade.sql @@ -1,3 +1,3 @@ -- Below script required to upgrade from 1.3.0-B2 to 1.3.0 -\c mosip_ida +\c :mosipdbname CREATE INDEX IF NOT EXISTS cred_event_store_status_cr_dtimes ON ida.credential_event_store USING btree (status_code desc, retry_count, cr_dtimes) WHERE status_code in ('NEW','FAILED'); \ No newline at end of file diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.1.2_to_1.3.0_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.1.2_to_1.3.0_rollback.sql index 67a4d53fbe..4d9589aa5e 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.1.2_to_1.3.0_rollback.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.1.2_to_1.3.0_rollback.sql @@ -1,7 +1,7 @@ -- ------------------------------------------------------------------------------------------ -- Rollback script for Migrating Spring batch version back from 5.0 as part of Java 21 Migration. -- ------------------------------------------------------------------------------------------ -\c mosip_ida +\c :mosipdbname TRUNCATE TABLE batch_job_execution CASCADE; TRUNCATE TABLE batch_job_execution_context CASCADE; TRUNCATE TABLE batch_job_execution_params CASCADE; @@ -11,7 +11,7 @@ TRUNCATE TABLE batch_step_execution_context CASCADE; GRANT usage, SELECT ON ALL SEQUENCES IN SCHEMA ida - TO idauser; + TO :dbuname; -- Revert ALTER on BATCH_STEP_EXECUTION ALTER TABLE BATCH_STEP_EXECUTION DROP COLUMN CREATE_TIME; -- Remove the column added diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.1.2_to_1.3.0_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.1.2_to_1.3.0_upgrade.sql index 0a4df1a3e1..612c26bc2f 100644 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.1.2_to_1.3.0_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.1.2_to_1.3.0_upgrade.sql @@ -1,7 +1,7 @@ -- ------------------------------------------------------------------------------------------ -- Upgrade script for Migrating Spring batch version to 5.0 as part of Java 21 Migration. -- ------------------------------------------------------------------------------------------ -\c mosip_ida +\c :mosipdbname ALTER TABLE BATCH_STEP_EXECUTION ADD CREATE_TIME TIMESTAMP NOT NULL DEFAULT '1970-01-01 00:00:00'; ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN START_TIME DROP NOT NULL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DATE_VAL; diff --git a/db_upgrade_scripts/mosip_ida/upgrade.properties b/db_upgrade_scripts/mosip_ida/upgrade.properties index 6226f1194f..33448b732e 100644 --- a/db_upgrade_scripts/mosip_ida/upgrade.properties +++ b/db_upgrade_scripts/mosip_ida/upgrade.properties @@ -1,4 +1,5 @@ -MOSIP_DB_NAME= +MOSIP_DB_NAME=mosip_ida +DB_UNAME=idauser DB_SERVERIP= DB_PORT= SU_USER=postgres diff --git a/db_upgrade_scripts/mosip_ida/upgrade.sh b/db_upgrade_scripts/mosip_ida/upgrade.sh index fe7b2f03d2..d034670947 100644 --- a/db_upgrade_scripts/mosip_ida/upgrade.sh +++ b/db_upgrade_scripts/mosip_ida/upgrade.sh @@ -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 @@ -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 @@ -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