Skip to content
Open
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
37 changes: 37 additions & 0 deletions src/main/resources/db/migration/dbiemr/V67__AMM_2035.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
USE db_iemr;

CREATE TABLE IF NOT EXISTS `anc_counselling_care` (
`id` bigint NOT NULL AUTO_INCREMENT,
`beneficiary_id` bigint NOT NULL,
`visit_date` date DEFAULT NULL,
`home_visit_date` date NOT NULL,
`anc_visit_id` bigint NOT NULL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

fd -t f "V67__AMM_2035.sql" src/main/resources/db/migration

Repository: PSMRI/AMRIT-DB

Length of output: 114


🏁 Script executed:

cat -n src/main/resources/db/migration/dbiemr/V67__AMM_2035.sql

Repository: PSMRI/AMRIT-DB

Length of output: 1879


🏁 Script executed:

cat -n src/main/resources/db/migration/dbiemr/V1__DB_IEMR.sql | grep -A 20 "CREATE TABLE.*t_anc_visit"

Repository: PSMRI/AMRIT-DB

Length of output: 1058


🏁 Script executed:

fd -t f "V[0-9]*.sql" src/main/resources/db/migration/dbiemr | sort -V | tail -20

Repository: PSMRI/AMRIT-DB

Length of output: 40


🏁 Script executed:

grep -r "fk_anc_counselling_care" src/main/resources/db/migration/dbiemr/

Repository: PSMRI/AMRIT-DB

Length of output: 40


🏁 Script executed:

grep -r "CONSTRAINT.*anc_visit" src/main/resources/db/migration/dbiemr/

Repository: PSMRI/AMRIT-DB

Length of output: 40


🏁 Script executed:

ls -1 src/main/resources/db/migration/dbiemr/ | grep "^V" | sort -V | tail -5

Repository: PSMRI/AMRIT-DB

Length of output: 197


🏁 Script executed:

grep -l "anc_counselling_care" src/main/resources/db/migration/dbiemr/*.sql

Repository: PSMRI/AMRIT-DB

Length of output: 114


🏁 Script executed:

ls -1 src/main/resources/db/migration/dbiemr/ | wc -l

Repository: PSMRI/AMRIT-DB

Length of output: 60


🏁 Script executed:

grep -n "FOREIGN KEY" src/main/resources/db/migration/dbiemr/V67__AMM_2035.sql

Repository: PSMRI/AMRIT-DB

Length of output: 40


🏁 Script executed:

grep -n "FOREIGN KEY" src/main/resources/db/migration/dbiemr/V1__DB_IEMR.sql | head -5

Repository: PSMRI/AMRIT-DB

Length of output: 914


Add a foreign key constraint for anc_visit_id to enforce referential integrity.

The anc_visit_id column at line 8 is declared as NOT NULL but lacks a foreign key constraint. The t_anc_visit table exists in V1__DB_IEMR.sql with a compatible id column type (bigint). Without the constraint, orphaned records and referential integrity violations are possible.

Suggested change
    `updated_by` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+   KEY `idx_anc_counselling_care_anc_visit_id` (`anc_visit_id`),
+   CONSTRAINT `fk_anc_counselling_care_anc_visit`
+     FOREIGN KEY (`anc_visit_id`) REFERENCES `t_anc_visit` (`id`),
    PRIMARY KEY (`id`)
πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/db/migration/dbiemr/V67__AMM_2035.sql` at line 8, Add a
foreign key constraint linking anc_visit_id to t_anc_visit(id) to enforce
referential integrity: alter the table definition in this migration so the
column anc_visit_id bigint NOT NULL includes a foreign key referencing
t_anc_visit(id) (and name the constraint e.g. fk_<table>_anc_visit_id or
similar), ensure ON DELETE/UPDATE behavior is set appropriately (e.g. ON DELETE
CASCADE or NO ACTION per domain rules), and verify the referenced t_anc_visit.id
is the same bigint type before applying the migration.

`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`select_all` tinyint(1) DEFAULT '0',
`swelling` tinyint(1) DEFAULT '0',
`high_bp` tinyint(1) DEFAULT '0',
`convulsions` tinyint(1) DEFAULT '0',
`anemia` tinyint(1) DEFAULT '0',
`reduced_fetal_movement` tinyint(1) DEFAULT '0',
`age_risk` tinyint(1) DEFAULT '0',
`child_gap` tinyint(1) DEFAULT '0',
`short_height` tinyint(1) DEFAULT '0',
`pre_preg_weight` tinyint(1) DEFAULT '0',
`bleeding` tinyint(1) DEFAULT '0',
`miscarriage_history` tinyint(1) DEFAULT '0',
`four_plus_delivery` tinyint(1) DEFAULT '0',
`first_delivery` tinyint(1) DEFAULT '0',
`twin_pregnancy` tinyint(1) DEFAULT '0',
`c_section_history` tinyint(1) DEFAULT '0',
`pre_existing_disease` tinyint(1) DEFAULT '0',
`fever_malaria` tinyint(1) DEFAULT '0',
`jaundice` tinyint(1) DEFAULT '0',
`sickle_cell` tinyint(1) DEFAULT '0',
`prolonged_labor` tinyint(1) DEFAULT '0',
`malpresentation` tinyint(1) DEFAULT '0',
`user_id` int DEFAULT NULL,
`created_by` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`updated_by` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ;
Loading