Skip to content

Commit

Permalink
Merge branch 'release-1.2.0.1' of https://github.com/mosip/pre-regist…
Browse files Browse the repository at this point in the history
…ration into develop
  • Loading branch information
aihamh committed Mar 25, 2024
2 parents fa17c60 + 4e9e71f commit 44a06ab
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\c mosip_prereg

REASSIGN OWNED BY postgres TO sysadmin;

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA prereg TO sysadmin;

DROP TABLE IF EXISTS prereg.applications;
DROP TABLE IF EXISTS prereg.anonymous_profile;

ALTER TABLE prereg.reg_appointment ADD CONSTRAINT fk_rappmnt_id FOREIGN KEY (prereg_id)
REFERENCES prereg.applicant_demographic(prereg_id) MATCH SIMPLE
ON DELETE NO ACTION ON UPDATE NO ACTION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
\c mosip_prereg

REASSIGN OWNED BY sysadmin TO postgres;

REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA prereg FROM prereguser;

REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA prereg FROM sysadmin;

GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ALL TABLES IN SCHEMA prereg TO prereguser;

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA prereg TO postgres;

CREATE TABLE IF NOT EXISTS prereg.applications(
application_id character varying(36) NOT NULL,
booking_type character varying(256) NOT NULL,
booking_status_code character varying(256),
application_status_code character varying(256),
regcntr_id character varying(10),
appointment_date date,
booking_date date,
slot_from_time time without time zone,
slot_to_time time without time zone,
contact_info character varying(256),
cr_by character varying(256) NOT NULL,
cr_dtimes timestamp without time zone NOT NULL,
upd_by character varying(256),
upd_dtimes timestamp without time zone,
CONSTRAINT appid_pk PRIMARY KEY (application_id)
);

GRANT SELECT,INSERT,UPDATE,DELETE,REFERENCES ON prereg.applications TO prereguser;

CREATE TABLE IF NOT EXISTS prereg.anonymous_profile
(
id character varying(36) NOT NULL,
profile character varying NOT NULL,
cr_by character varying(256) NOT NULL,
cr_dtimes timestamp without time zone NOT NULL,
upd_by character varying(256),
upd_dtimes timestamp without time zone,
is_deleted boolean,
del_dtimes timestamp without time zone,
CONSTRAINT anonymous_profile_pkey PRIMARY KEY (id)
);

GRANT SELECT,INSERT,UPDATE,DELETE,REFERENCES ON prereg.anonymous_profile TO prereguser;

ALTER TABLE prereg.reg_appointment DROP CONSTRAINT IF EXISTS fk_rappmnt_id CASCADE;

CREATE INDEX IF NOT EXISTS idx_app_demo_cr_by ON prereg.applicant_demographic USING btree (cr_by COLLATE pg_catalog."default" ASC NULLS LAST) TABLESPACE pg_default;
CREATE INDEX IF NOT EXISTS idx_app_demo_prid ON prereg.applicant_demographic USING btree (prereg_id COLLATE pg_catalog."default" ASC NULLS LAST) TABLESPACE pg_default;

ALTER TABLE prereg.prid_seq RENAME TO prid_seq_to_be_deleted;
ALTER TABLE prereg.transaction_type RENAME TO transaction_type_to_be_deleted;
ALTER TABLE prereg.language_transliteration RENAME TO language_transliteration_to_be_deleted;
ALTER TABLE prereg.prid_seed RENAME TO prid_seed_to_be_deleted;
ALTER TABLE prereg.pre_registration_transaction RENAME TO pre_registration_transaction_to_be_deleted;
ALTER TABLE prereg.processed_prereg_list DROP CONSTRAINT IF EXISTS pprlst_pregtrn_fk CASCADE;

INSERT INTO prereg.applications(application_id, booking_type, booking_status_code, regcntr_id, appointment_date, booking_date,
slot_from_time, slot_to_time, contact_info, cr_by, cr_dtimes, upd_by, upd_dtimes, application_status_code)
Select t1.prereg_id, 'NEW_PREREGISTRATION', t1.status_code, t2.regcntr_id, t2.appointment_date,
t2.booking_dtimes, t2.slot_from_time, t2.slot_to_time, t1.cr_appuser_id, t1.cr_by, t1.cr_dtimes, t1.upd_by, t1.upd_dtimes,
Case When t1.status_code='Application_Incomplete' THEN 'DRAFT' Else 'SUBMITTED' End
From prereg.applicant_demographic t1
LEFT Join prereg.reg_appointment t2 On t1.prereg_id=t2.prereg_id;

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION'
12 changes: 12 additions & 0 deletions db_upgrade_scripts/mosip_prereg/upgrade.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
MOSIP_DB_NAME=
DB_SERVERIP=
DB_PORT=
SU_USER=postgres
SU_USER_PWD=
SYS_ADMIN_USER=
SYS_ADMIN_PWD=
DEFAULT_DB_NAME=postgres
DBUSER_PWD=
ACTION=
CURRENT_VERSION=
UPGRADE_VERSION=
51 changes: 51 additions & 0 deletions db_upgrade_scripts/mosip_prereg/upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

set -e
properties_file="$1"
echo `date "+%m/%d/%Y %H:%M:%S"` ": $properties_file"
if [ -f "$properties_file" ]
then
echo `date "+%m/%d/%Y %H:%M:%S"` ": Property file \"$properties_file\" found."
while IFS='=' read -r key value
do
key=$(echo $key | tr '.' '_')
eval ${key}=\${value}
done < "$properties_file"
else
echo `date "+%m/%d/%Y %H:%M:%S"` ": Property file not found, Pass property file name as argument."
fi

echo "Current version: $CURRENT_VERSION"
echo "UPGRADE version: $UPGRADE_VERSION"
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;)
echo "Terminated connections"

# Execute upgrade or rollback
if [ "$ACTION" == "upgrade" ]; then
echo "Upgrading database from $CURRENT_VERSION to $UPGRADE_VERSION"
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
else
echo "Upgrade script not found, exiting."
exit 1
fi
elif [ "$ACTION" == "rollback" ]; then
echo "Rolling back database for $CURRENT_VERSION to $UPGRADE_VERSION"
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
else
echo "rollback script not found, exiting."
exit 1
fi
else
echo "Unknown action: $ACTION, must be 'upgrade' or 'rollback'."
exit 1
fi

0 comments on commit 44a06ab

Please sign in to comment.