Data Migration
Proposed Changes
- Lost of data migration logic
- More than 6k lines of code written with copilot and rewritten without it
Merge Checklist
- [ ] Tests added/fixed
- [ ] Update docs in
/docs - [ ] Linting Complete
- [ ] Any other necessary step
Only PR's with test cases included and passing lint and test pipelines will be reviewed
@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins
Summary by CodeRabbit
Summary by CodeRabbit
-
New Features
- Enhanced data migration across core modules—including patient records, consultations, consents, prescriptions, daily rounds, and facility/asset management—improving data integrity and system reliability.
- Expanded role-based access with new read-only roles for nurses, staff, and administrators.
- Introduced a new configuration option to determine if the application is in a testing state.
- Added support for tracking data migrations with a new
MigrationTrackingmodel. - Added new fields for migrated identifiers in various models, enhancing data tracking capabilities.
-
Chores
- Updated backend schemas and migration tracking processes, alongside utility improvements, to streamline operations and support future enhancements.
[!NOTE]
Reviews paused
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
📝 Walkthrough
Walkthrough
This pull request broadens the ignore pattern in the .gitignore file and introduces a skip directive in one EMR models file. Multiple migration scripts have been added or enhanced to handle data transformations and reverse operations for organizations, users, facilities, patient registrations and consultations, notes, prescriptions, symptoms, diagnoses, file uploads, daily rounds, assets, and consent records. Core models have been updated with new fields to track migrated EMR identifiers, and a new migration tracking model has been added. Additional utilities, role definitions, and testing configuration variables are also introduced. Quite the busy little update, isn’t it?
Changes
| File(s) | Change Summary |
|---|---|
.gitignore |
Updated ignore pattern for care_db.dump from a fixed filename to a wildcard pattern (care_db.dump*). |
care/emr/models/__init__.py |
Added # isort: skip_file directive at the top to bypass import sorting. |
care/facility/migrations/0477_*.py.../0491_migrate_consent_records.py |
Multiple migration scripts updated/created to migrate organizations, users, facilities, patient registrations, consultations, notes, prescriptions, symptoms, diagnoses, file uploads, daily rounds, assets, and consent records, including new functions, reverse functions, and a new migration tracking model. |
care/facility/models/{__init__.py, asset.py, bed.py, migration_tracking.py, patient.py, patient_consultation.py} |
New fields for migrated EMR identifiers added in PatientRegistration, PatientNotes, Asset, Bed, AssetLocation, and PatientConsultation; added new model MigrationTracking and updated import and permission logic. |
care/facility/utils.py |
Introduced new utility functions enable_auto_time and disable_auto_time for managing automatic timestamping on models. |
care/security/roles/role.py |
Added new read-only roles (NURSE_READONLY_ROLE, STAFF_READONLY_ROLE, GEO_ADMIN_READONLY_ROLE) and updated role mapping logic for legacy roles. |
config/settings/{base.py, test.py} |
Added a new TESTING configuration variable (set to False in base and True in test settings). |
Sequence Diagram(s)
sequenceDiagram
participant M as Migration Script
participant Q as Query/Pagination
participant T as Transformation Logic
participant DB as Database
M->>Q: Fetch batch of records to migrate
Q-->>M: Return records
M->>T: Transform data for new schema
T-->>M: Return transformed records
M->>DB: Bulk insert/update transformed data
DB-->>M: Confirm write
M->>M: Log migration completion
Suggested Reviewers
- vigneshhari
Poem
In the maze of migrations our code took flight,
With fields and functions emerging in the night.
From rigid names to patterns set free,
Data sings its new migration melody.
A subtle nod (and a wink) to bugs left behind—
Cheers to changes, reformed and refined!(May our migrations be as smooth as they are unavoidable.)
✨ Finishing Touches
🧪 Generate Unit Tests
- [ ] Create PR with Unit Tests
- [ ] Post Copyable Unit Tests in a Comment
- [ ] Commit Unit Tests in branch
data-migration
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai auto-generate unit teststo generate unit tests for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 51.33%. Comparing base (05dd61f) to head (5d9e267).
:warning: Report is 329 commits behind head on develop.
Additional details and impacted files
@@ Coverage Diff @@
## develop #2763 +/- ##
===========================================
+ Coverage 51.18% 51.33% +0.14%
===========================================
Files 251 251
Lines 11403 11406 +3
Branches 1284 1285 +1
===========================================
+ Hits 5837 5855 +18
+ Misses 5545 5527 -18
- Partials 21 24 +3
: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.
[!NOTE] Generated docstrings for this pull request at https://github.com/ohcnetwork/care/pull/2899
@coderabbitai pause
:white_check_mark: Actions performed
Reviews paused.