Skip to content

Commit

Permalink
MOSIP-32453 : Added upgrade and rollback scripts for spring batch jav…
Browse files Browse the repository at this point in the history
…a migration (#1073)

* Added upgrade and rollback scripts for spring batch java migration

Signed-off-by: GOKULRAJ136 <110164849+GOKULRAJ136@users.noreply.github.com>

* Added cleanup.sql and taken a backup before deleting other lang data

Signed-off-by: GOKULRAJ136 <110164849+GOKULRAJ136@users.noreply.github.com>

---------

Signed-off-by: GOKULRAJ136 <110164849+GOKULRAJ136@users.noreply.github.com>
  • Loading branch information
GOKULRAJ136 authored Nov 27, 2024
1 parent 2435755 commit 35ba58e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 46 deletions.
30 changes: 30 additions & 0 deletions db_scripts/mosip_master/default_data_cleanup/cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
DELETE FROM master.template_file_format
WHERE lang_code !='eng';

DELETE FROM master.authentication_method
WHERE lang_code !='eng';

DELETE FROM master.app_detail
WHERE lang_code !='eng';

DELETE FROM master.biometric_type
WHERE lang_code !='eng';

DELETE FROM master.biometric_attribute
WHERE lang_code !='eng';

DELETE FROM master.module_detail
WHERE lang_code !='eng';


drop table master.admin_param;
drop table master.appl_form_type;
drop table master.message_list;
drop table master.doc_format;
drop table master.gender;
drop table master.global_param;
drop table master.id_type;
drop table master.individual_type;
drop table master.introducer_type;
drop table master.status_list;
drop table master.status_type;
Original file line number Diff line number Diff line change
@@ -1,23 +1 @@
-- Rollback script for master.app_detail
ALTER TABLE master.app_detail ALTER COLUMN lang_code SET NOT NULL;
ALTER TABLE master.app_detail DROP CONSTRAINT pk_appdtl_id;
ALTER TABLE master.app_detail ADD CONSTRAINT pk_appdtl_id PRIMARY KEY (id, lang_code);

-- Rollback script for master.biometric_attribute
ALTER TABLE master.biometric_attribute ALTER COLUMN lang_code SET NOT NULL;
ALTER TABLE master.biometric_attribute DROP CONSTRAINT pk_bmattr_code;
ALTER TABLE master.biometric_attribute ADD CONSTRAINT pk_bmattr_code PRIMARY KEY (code, lang_code);

-- Rollback script for master.module_detail
ALTER TABLE master.module_detail ALTER COLUMN lang_code SET NOT NULL;
ALTER TABLE master.module_detail DROP CONSTRAINT pk_moddtl_code;
ALTER TABLE master.module_detail ADD CONSTRAINT pk_moddtl_code PRIMARY KEY (id, lang_code);

-- Rollback script for master.template_file_format
ALTER TABLE master.template DROP CONSTRAINT IF EXISTS fk_tmplt_tffmt CASCADE;
ALTER TABLE master.template_file_format ALTER COLUMN lang_code SET NOT NULL;
ALTER TABLE master.template_file_format DROP CONSTRAINT pk_tffmt_code;
ALTER TABLE master.template_file_format ADD CONSTRAINT pk_tffmt_code PRIMARY KEY (code, lang_code);

-- Rollback script for master.template
ALTER TABLE master.template ADD CONSTRAINT fk_tmplt_tffmt FOREIGN KEY (file_format_code, lang_code) REFERENCES master.template_file_format (code, lang_code);
\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION'
Original file line number Diff line number Diff line change
@@ -1,23 +1 @@
-- Upgrade script for master.app_detail
ALTER TABLE master.app_detail DROP CONSTRAINT IF EXISTS pk_appdtl_id CASCADE;
ALTER TABLE master.app_detail ALTER COLUMN lang_code DROP NOT NULL;
ALTER TABLE master.app_detail ADD CONSTRAINT pk_appdtl_id PRIMARY KEY (id);

-- Upgrade script for master.biometric_attribute
ALTER TABLE master.biometric_attribute DROP CONSTRAINT IF EXISTS pk_bmattr_code CASCADE;
ALTER TABLE master.biometric_attribute ALTER COLUMN lang_code DROP NOT NULL;
ALTER TABLE master.biometric_attribute ADD CONSTRAINT pk_bmattr_code PRIMARY KEY (code);

-- Upgrade script for master.module_detail
ALTER TABLE master.module_detail DROP CONSTRAINT IF EXISTS pk_moddtl_code CASCADE;
ALTER TABLE master.module_detail ALTER COLUMN lang_code DROP NOT NULL;
ALTER TABLE master.module_detail ADD CONSTRAINT pk_moddtl_code PRIMARY KEY (id);

-- Upgrade script for master.template_file_format
ALTER TABLE master.template DROP CONSTRAINT IF EXISTS fk_tmplt_tffmt CASCADE;
ALTER TABLE master.template_file_format DROP CONSTRAINT IF EXISTS pk_tffmt_code CASCADE;
ALTER TABLE master.template_file_format ALTER COLUMN lang_code DROP NOT NULL;
ALTER TABLE master.template_file_format ADD CONSTRAINT pk_tffmt_code PRIMARY KEY (code);

-- Upgrade script for master.template
ALTER TABLE master.template ADD CONSTRAINT fk_tmplt_tffmt FOREIGN KEY (file_format_code) REFERENCES master.template_file_format (code);
\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION'
32 changes: 32 additions & 0 deletions db_upgrade_scripts/mosip_master/sql/1.2.1.0_to_1.3.0_rollback.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
-- Rollback script for master.app_detail
INSERT INTO master.app_detail SELECT * FROM master.app_detail_bkp;
ALTER TABLE master.app_detail ALTER COLUMN lang_code SET NOT NULL;
ALTER TABLE master.app_detail DROP CONSTRAINT pk_appdtl_id;
ALTER TABLE master.app_detail ADD CONSTRAINT pk_appdtl_id PRIMARY KEY (id, lang_code);
DROP TABLE IF EXISTS master.app_detail_bkp;

-- Rollback script for master.biometric_attribute
INSERT INTO master.biometric_attribute SELECT * FROM master.biometric_attribute_bkp;
ALTER TABLE master.biometric_attribute ALTER COLUMN lang_code SET NOT NULL;
ALTER TABLE master.biometric_attribute DROP CONSTRAINT pk_bmattr_code;
ALTER TABLE master.biometric_attribute ADD CONSTRAINT pk_bmattr_code PRIMARY KEY (code, lang_code);
DROP TABLE IF EXISTS master.biometric_attribute_bkp;

-- Rollback script for master.module_detail
INSERT INTO master.module_detail SELECT * FROM master.module_detail_bkp;
ALTER TABLE master.module_detail ALTER COLUMN lang_code SET NOT NULL;
ALTER TABLE master.module_detail DROP CONSTRAINT pk_moddtl_code;
ALTER TABLE master.module_detail ADD CONSTRAINT pk_moddtl_code PRIMARY KEY (id, lang_code);
DROP TABLE IF EXISTS master.module_detail;

-- Rollback script for master.template_file_format
INSERT INTO master.template_file_format SELECT * FROM master.template_file_format_bkp;
ALTER TABLE master.template DROP CONSTRAINT IF EXISTS fk_tmplt_tffmt CASCADE;
ALTER TABLE master.template_file_format ALTER COLUMN lang_code SET NOT NULL;
ALTER TABLE master.template_file_format DROP CONSTRAINT pk_tffmt_code;
ALTER TABLE master.template_file_format ADD CONSTRAINT pk_tffmt_code PRIMARY KEY (code, lang_code);
DROP TABLE IF EXISTS master.template_file_format;

-- Rollback script for master.template
ALTER TABLE master.template ADD CONSTRAINT fk_tmplt_tffmt FOREIGN KEY (file_format_code, lang_code) REFERENCES master.template_file_format (code, lang_code);

-- ------------------------------------------------------------------------------------------
-- Rollback script for Migrating Spring batch version to 5.0 as part of Java 21 Migration.
-- ------------------------------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions db_upgrade_scripts/mosip_master/sql/1.2.1.0_to_1.3.0_upgrade.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
-- Upgrade script for master.app_detail
SELECT * INTO master.app_detail_bkp FROM master.app_detail;
DELETE FROM master.app_detail WHERE lang_code !='eng';
ALTER TABLE master.app_detail DROP CONSTRAINT IF EXISTS pk_appdtl_id CASCADE;
ALTER TABLE master.app_detail ALTER COLUMN lang_code DROP NOT NULL;
ALTER TABLE master.app_detail ADD CONSTRAINT pk_appdtl_id PRIMARY KEY (id);

-- Upgrade script for master.biometric_attribute
SELECT * INTO master.biometric_attribute_bkp FROM master.biometric_attribute;
DELETE FROM master.biometric_attribute WHERE lang_code !='eng';
ALTER TABLE master.biometric_attribute DROP CONSTRAINT IF EXISTS pk_bmattr_code CASCADE;
ALTER TABLE master.biometric_attribute ALTER COLUMN lang_code DROP NOT NULL;
ALTER TABLE master.biometric_attribute ADD CONSTRAINT pk_bmattr_code PRIMARY KEY (code);

-- Upgrade script for master.module_detail
SELECT * INTO master.module_detail_bkp FROM master.module_detail;
DELETE FROM master.module_detail WHERE lang_code !='eng';
ALTER TABLE master.module_detail DROP CONSTRAINT IF EXISTS pk_moddtl_code CASCADE;
ALTER TABLE master.module_detail ALTER COLUMN lang_code DROP NOT NULL;
ALTER TABLE master.module_detail ADD CONSTRAINT pk_moddtl_code PRIMARY KEY (id);

-- Upgrade script for master.template_file_format
SELECT * INTO master.template_file_format_bkp FROM master.template_file_format;
ALTER TABLE master.template DROP CONSTRAINT IF EXISTS fk_tmplt_tffmt CASCADE;
ALTER TABLE master.template_file_format DROP CONSTRAINT IF EXISTS pk_tffmt_code CASCADE;
DELETE FROM master.template_file_format WHERE lang_code !='eng';
ALTER TABLE master.template_file_format ALTER COLUMN lang_code DROP NOT NULL;
ALTER TABLE master.template_file_format ADD CONSTRAINT pk_tffmt_code PRIMARY KEY (code);

-- Upgrade script for master.template
ALTER TABLE master.template ADD CONSTRAINT fk_tmplt_tffmt FOREIGN KEY (file_format_code) REFERENCES master.template_file_format (code);

-- ------------------------------------------------------------------------------------------
-- Upgrade script for Migrating Spring batch version to 5.0 as part of Java 21 Migration.
-- ------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 35ba58e

Please sign in to comment.