forked from mosip/esignet-mock-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Venkata Saidurga Polamraju <saidurgacsea@gmail.com>
- Loading branch information
1 parent
3ed8c7c
commit 0235998
Showing
9 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Directory contains sql scripts to be executed for DB migrations. upgrade and revoke scripts are named after the migrated version. |
1 change: 1 addition & 0 deletions
1
db_upgrade_script/mosip_mockidentitysystem/sql/0.9.0_to_0.9.1_rollback.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\echo 'Rollback Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION' |
1 change: 1 addition & 0 deletions
1
db_upgrade_script/mosip_mockidentitysystem/sql/0.9.0_to_0.9.1_upgrade.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
1 change: 1 addition & 0 deletions
1
db_upgrade_script/mosip_mockidentitysystem/sql/0.9.1_to_0.9.2_rollback.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\echo 'Rollback Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION' |
1 change: 1 addition & 0 deletions
1
db_upgrade_script/mosip_mockidentitysystem/sql/0.9.1_to_0.9.2_upgrade.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
1 change: 1 addition & 0 deletions
1
db_upgrade_script/mosip_mockidentitysystem/sql/0.9.2_to_0.9.3_rollback.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\echo 'Rollback Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION' |
1 change: 1 addition & 0 deletions
1
db_upgrade_script/mosip_mockidentitysystem/sql/0.9.2_to_0.9.3_upgrade.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
db_upgrade_script/mosip_mockidentitysystem/upgrade.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
ACTION=upgrade | ||
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= | ||
CURRENT_VERSION= | ||
UPGRADE_VERSION= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -v primary_language_code=$PRIMARY_LANGUAGE_CODE -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 -v primary_language_code=$PRIMARY_LANGUAGE_CODE -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 |