Squash facility and user migrations
- Squash all migrations
Migration changes
./manage.py showmigrations admin [X] 0001_initial [X] 0002_logentry_remove_auto_add [X] 0003_logentry_add_action_flag_choices auth [X] 0001_initial [X] 0002_alter_permission_name_max_length [X] 0003_alter_user_email_max_length [X] 0004_alter_user_username_opts [X] 0005_alter_user_last_login_null [X] 0006_require_contenttypes_0002 [X] 0007_alter_validators_add_error_messages [X] 0008_alter_user_username_max_length [X] 0009_alter_user_last_name_max_length [X] 0010_alter_group_name_max_length [X] 0011_update_proxy_permissions [X] 0012_alter_user_first_name_max_length authtoken [X] 0001_initial [X] 0002_auto_20160226_1747 [X] 0003_tokenproxy [X] 0004_alter_tokenproxy_options contenttypes [X] 0001_initial [X] 0002_remove_content_type_name emr [X] 0001_initial [X] 0002_questionnaire_tags_questionnairetag [X] 0003_questionnairetag_slug [X] 0002_alter_patient_gender [X] 0004_merge_20250108_1244 [X] 0005_alter_availability_slot_size_in_minutes_and_more [X] 0006_alter_patient_blood_group [X] 0007_remove_medicationrequest_authored_on_and_more [X] 0008_medicationrequest_medication [X] 0009_medicationrequest_authored_on [X] 0010_condition_abatement [X] 0011_medicationrequest_requester [X] 0012_alter_condition_encounter [X] 0013_facilitylocation_facilitylocationorganization [X] 0014_encounter_current_location_facilitylocationencounter [X] 0015_facilitylocation_availability_status_and_more [X] 0016_allergyintolerance_copied_from [X] 0017_remove_facilitylocation_availability_status_and_more [X] 0018_consent_device_deviceencounterhistory_and_more [X] 0019_consent_note [X] 0020_observation_component [X] 0021_metaartifact [X] 0022_facilitylocation_sort_index [X] 0023_uservaluesetpreference [X] 0023_allergyintolerance_allergy_intolerance_type [X] 0024_merge_20250320_2002 [X] 0025_alter_tokenbooking_token_slot [X] 0026_encounter_treating_doctors [X] 0027_rename_treating_doctors_encounter_care_team [X] 0028_alter_encounter_care_team [X] 0029_encounter_discharge_summary_advice [X] 0030_encounter_tags_medicationrequest_dispense_status_and_more [X] 0031_rename_reason_for_visit_tokenbooking_note [X] 0032_tokenbooking_associated_encounter [X] 0033_healthcareservice_managing_organization [X] 0034_token_system [X] 0035_remove_tagconfig_slug [X] 0036_deliveryorder_supplydelivery_order_dispenseorder_and_more [X] 0037_deliveryorder_destination_deliveryorder_origin_and_more [X] 0038_paymentreconciliation_location [X] 0039_formsubmission_questionnaireresponse_form_submission [X] 0040_template_reportupload [X] 0041_template_options [X] 0040_alter_observation_interpretation [X] 0042_merge_20251209_2240 facility [-] 0001_new_initial (1 squashed migrations) Run 'manage.py migrate' to finish recording. [-] 0002_new_initial (4 squashed migrations) Run 'manage.py migrate' to finish recording. security [X] 0001_initial [X] 0002_remove_rolemodel_unique_order_and_more [X] 0003_migrate_default_role_change [X] 0004_alter_rolemodel_name_and_more [X] 0005_rolemodel_is_archived sessions [X] 0001_initial sites [X] 0001_initial [X] 0002_alter_domain_unique [X] 0003_set_site_domain_and_name [X] 0004_alter_site_options users [-] 0001_new_initial (1 squashed migrations) Run 'manage.py migrate' to finish recording. [-] 0002_new_initial (1 squashed migrations) Run 'manage.py migrate' to finish recording.
./manage.py migrate Operations to perform: Apply all migrations: admin, auth, authtoken, contenttypes, emr, facility, security, sessions, sites, users Running migrations: No migrations to apply.
📝 Walkthrough
Walkthrough
This diff consolidates Django migrations across multiple apps (EMR, Facility, and Users) by introducing new initial migrations that replace numerous legacy migrations. Existing migrations in EMR are updated to reference new facility initial migrations, while Facility and Users apps undergo significant migration cleanup with old migrations deleted and new initial migrations created to establish current schema state.
Changes
| Cohort / File(s) | Summary |
|---|---|
EMR Migration Dependencies care/emr/migrations/0001_initial.py, care/emr/migrations/0013_facilitylocation_facilitylocationorganization.py, care/emr/migrations/0018_consent_device_deviceencounterhistory_and_more.py, care/emr/migrations/0030_encounter_tags_medicationrequest_dispense_status_and_more.py, care/emr/migrations/0034_token_system.py, care/emr/migrations/0036_deliveryorder_supplydelivery_order_dispenseorder_and_more.py, care/emr/migrations/0040_template_reportupload.py |
Updated facility app dependencies from late-stage migrations (0475_merge, 0476_facility_default_*, 0478_facility_discount_*) to new initial migrations (0001_new_initial, 0002_new_initial) |
Facility App: New Initial Migrations care/facility/migrations/0001_new_initial.py |
Introduces initial migration creating Facility, FacilityFlag, and PatientMobileOTP models with comprehensive field definitions, validators, and metadata |
Facility App: Replaces Consolidation care/facility/migrations/0002_new_initial.py |
Initial migration marked to replace migrations 0378–0478, adds created_by, default_internal_organization, geo_organization FK fields and facilityflag facility FK with unique constraint |
Facility App: Extensive Migration Cleanup care/facility/migrations/0002_auto_20230613_1657.py through care/facility/migrations/0024_remove_user_district_remove_localbody_district_and_more.py |
Deleted 470+ individual migrations spanning data transformations (e.g., 0363_auto_20230621_1857, 0429_double_pain_scale), schema alterations (field type changes, renames, additions), model creations (EventType, PatientConsultationEvent, EncounterSymptom, ConsultationDiagnosis), model deletions, and constraint management |
Users App: New Initial Migrations care/users/migrations/0001_new_initial.py |
Introduces initial migration creating PlugConfig, User, and UserFlag models with authentication, profile, contact, and MFA fields |
Users App: New Follow-up Migration care/users/migrations/0002_new_initial.py |
Initial migration marked to replace prior migrations, adds geo_organization FK to User model |
Users App: Legacy Migration Cleanup care/users/migrations/0001_initial_squashed.py and care/users/migrations/0002_auto_20230613_1622.py through care/users/migrations/0024_remove_user_district_remove_localbody_district_and_more.py |
Deleted 24 migrations including squashed initial, data migrations (skill renames, age-to-dateofbirth conversion), model creations, and field/constraint removals |
Users Models care/users/models.py |
Removed Skill and UserSkill model classes and skills M2M field from User model; simplified imports |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Areas requiring extra attention:
-
Migration dependency chain integrity: Verify that all EMR migrations now correctly resolve dependencies through the new facility initial migrations (
0001_new_initial,0002_new_initial); confirm no orphaned or circular dependencies exist across the three apps -
Data preservation across consolidation: Confirm the new facility
0002_new_initial.pymigration with itsreplaceslist correctly supersedes migrations 0378–0478 without data loss; validate that theUniqueConstrainton facilityflag and foreign key relationships are properly established -
Model removal impact in Users: Validate removal of Skill and UserSkill models—verify no active code paths reference these models or the removed
skillsM2M relationship; check for dangling imports or serializers that depend on these entities - Schema changes in Facility: The new initial migration consolidates significant schema state; review the Facility model's extensive field set (features ArrayField, discount_codes/monetary_components JSONField, phone_number validator) to ensure it reflects the intended final schema
-
Reverse migration feasibility: Although these are initial migrations, confirm the
replacesdirectives and operations are reversible if needed for development/testing environments
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | ⚠️ Warning | The pull request description is completely empty, missing all required sections: Proposed Changes, Associated Issue, and Merge Checklist are absent. | Add a comprehensive description following the template: explain what migrations were squashed, why this change was necessary, link any related issues, and complete the merge checklist. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title 'Squash facility and user migrations' clearly describes the main change—consolidating/squashing migrations for two app modules. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
sainak/major-migration-squash
Comment @coderabbitai help to get the list of available commands and usage tips.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 74.84%. Comparing base (f9e395b) to head (bb03e56).
Additional details and impacted files
@@ Coverage Diff @@
## develop #3410 +/- ##
===========================================
- Coverage 74.85% 74.84% -0.01%
===========================================
Files 449 449
Lines 20412 20412
Branches 2114 2114
===========================================
- Hits 15279 15277 -2
- Misses 4677 4679 +2
Partials 456 456
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.