Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(j-s): Migration #16742

Merged
merged 2 commits into from
Nov 6, 2024
Merged

fix(j-s): Migration #16742

merged 2 commits into from
Nov 6, 2024

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Nov 6, 2024

Migration

What

  • Fixes migration

Why

  • Verified bug

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • Bug Fixes
    • Updated column names in the judicial system's database for improved consistency and clarity.
    • Renamed columns from camelCase to snake_case for better readability.

@gudjong gudjong requested a review from a team as a code owner November 6, 2024 12:54
Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes in this pull request involve modifications to a migration script for the judicial system's database. Specifically, the up method of the migration has been updated to change column names in the case table from camelCase to snake_case. The affected columns include prosecutorPostponedAppealDate, accusedPostponedAppealDate, and appealState, which have been renamed to prosecutor_postponed_appeal_date, accused_postponed_appeal_date, and appeal_state, respectively. The down method remains unchanged.

Changes

File Path Change Summary
apps/judicial-system/backend/migrations/... Updated column names in bulkUpdate calls for case table from camelCase to snake_case.

Possibly related PRs

  • fix(j-s): Notification migration #16378: This PR modifies the up and down migration functions for the notification table, which is related to database migrations similar to the changes made in the main PR for the case table.
  • chore(j-s): Delete indictments before launch #16536: This PR introduces a migration that updates the state column of records in the case table, which directly relates to the changes made in the main PR that also modifies the case table.
  • fix(j-s): Notification Type #16538: This PR changes the type column in the notification table from an ENUM to a STRING, which is another migration-related change that aligns with the migration focus of the main PR.
  • fix(j-s): Handling of wrong appeal info #16643: This PR enhances the handling of appeal information, which involves changes to the appealState property in the context of case management, similar to the updates made in the main PR regarding the case table.

Suggested labels

automerge

Suggested reviewers

  • unakb

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 generate unit testing code.
    • @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.

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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
apps/judicial-system/backend/migrations/20241101152701-correct-appealed-cases.js (1)

Line range hint 8-50: Consider consolidating the bulkUpdate operations

The current implementation uses multiple bulkUpdate operations for similar changes. This could be simplified into fewer operations by grouping cases that require the same field updates.

Consider refactoring to something like this:

- queryInterface.bulkUpdate(
-   'case',
-   { prosecutor_postponed_appeal_date: null },
-   {
-     id: [
-       '7ee802fa-cfcd-48e6-b198-ea6c53a2ddd0',
-       '133b1a36-e4c3-42d6-8293-0bd57bddc40b',
-       '0e1dd971-8958-4e2e-9c81-940c2bd10909',
-     ],
-   },
-   { transaction },
- ),
- // ... other individual updates ...

+ // Group 1: Cases that need all fields nullified
+ queryInterface.bulkUpdate(
+   'case',
+   {
+     appeal_state: null,
+     prosecutor_postponed_appeal_date: null,
+     accused_postponed_appeal_date: null,
+   },
+   {
+     id: [
+       'd909a866-7ed0-45ed-86c1-2445a7475e4e',
+       '798e8e75-e853-48b3-a15d-1fbfcd018f98'
+     ],
+   },
+   { transaction },
+ ),
+ // Group 2: Cases that need only prosecutor_postponed_appeal_date nullified
+ queryInterface.bulkUpdate(
+   'case',
+   { prosecutor_postponed_appeal_date: null },
+   {
+     id: [
+       '7ee802fa-cfcd-48e6-b198-ea6c53a2ddd0',
+       '133b1a36-e4c3-42d6-8293-0bd57bddc40b',
+       '0e1dd971-8958-4e2e-9c81-940c2bd10909',
+     ],
+   },
+   { transaction },
+ ),
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 85f8c21 and 4adf4d5.

📒 Files selected for processing (1)
  • apps/judicial-system/backend/migrations/20241101152701-correct-appealed-cases.js (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/backend/migrations/20241101152701-correct-appealed-cases.js (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
📓 Learnings (1)
apps/judicial-system/backend/migrations/20241101152701-correct-appealed-cases.js (1)
Learnt from: oddsson
PR: island-is/island.is#16495
File: apps/judicial-system/backend/migrations/20241022142128-update-defendant.js:18-24
Timestamp: 2024-10-25T14:06:40.795Z
Learning: When rolling back migrations, if the associated code that uses the fields is also rolled back, data preservation concerns may not be an issue.
🔇 Additional comments (3)
apps/judicial-system/backend/migrations/20241101152701-correct-appealed-cases.js (3)

Line range hint 4-8: Well-structured migration with proper transaction handling!

The migration follows best practices by using a transaction and Promise.all for atomic execution of multiple updates.


Line range hint 52-54: Verify if empty down migration is intentional

The down migration is empty, which means these changes cannot be rolled back. Based on previous learnings, this might be acceptable if the associated code changes are also rolled back, but please confirm if this is intentional.

Let's check if there are any dependent changes:

✅ Verification successful

Empty down migration is acceptable in this case

This migration is specifically correcting data issues by nullifying incorrect values in specific cases (identified by UUIDs). Since this is a data cleanup migration fixing invalid states, having an empty down migration is appropriate because:

  1. The migration only affects a fixed set of cases with specific UUIDs
  2. The changes reset invalid data to null rather than transforming valid data
  3. The fields being modified (prosecutor_postponed_appeal_date, accused_postponed_appeal_date, appeal_state) are still actively used in the codebase for appeal handling

Attempting to restore potentially invalid data would be more risky than helpful.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for related code changes that might depend on these column names
# Expected: Should show any code references to these fields

echo "Checking for code references to the affected fields..."
rg -l "prosecutor_postponed_appeal_date|accused_postponed_appeal_date|appeal_state" \
   --type ts \
   --type js \
   -g '!**/migrations/*'

Length of output: 561


Script:

#!/bin/bash
# Let's check the content of these files to understand the usage
echo "=== Checking notifications.ts ==="
rg -A 5 -B 5 "prosecutor_postponed_appeal_date|accused_postponed_appeal_date|appeal_state" "apps/judicial-system/backend/src/app/messages/notifications.ts"

echo -e "\n=== Checking cases.filter.ts ==="
rg -A 5 -B 5 "prosecutor_postponed_appeal_date|accused_postponed_appeal_date|appeal_state" "apps/judicial-system/backend/src/app/modules/case/filters/cases.filter.ts"

echo -e "\n=== Checking useAppealAlertBanner.strings.ts ==="
rg -A 5 -B 5 "prosecutor_postponed_appeal_date|accused_postponed_appeal_date|appeal_state" "apps/judicial-system/web/src/utils/hooks/useAppealAlertBanner/useAppealAlertBanner.strings.ts"

# Also let's check the migration file to understand what's being changed
echo -e "\n=== Checking the migration file ==="
cat "apps/judicial-system/backend/migrations/20241101152701-correct-appealed-cases.js"

Length of output: 4721


9-9: Verify the impact of setting all values to null

The migration sets multiple appeal-related fields to null across different cases. This could potentially lead to data loss if these fields currently contain important information.

Let's check the current values before proceeding:

Also applies to: 22-22, 30-31, 41-43

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 6, 2024

Datadog Report

Branch report: j-s/fix-migration
Commit report: a56b787
Test service: judicial-system-backend

✅ 0 Failed, 21195 Passed, 0 Skipped, 0s Total Time

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.54%. Comparing base (8bdbd53) to head (4adf4d5).
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16742   +/-   ##
=======================================
  Coverage   36.54%   36.54%           
=======================================
  Files        6890     6890           
  Lines      143640   143640           
  Branches    40926    40926           
=======================================
  Hits        52488    52488           
  Misses      91152    91152           
Flag Coverage Δ
judicial-system-backend 55.17% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 85f8c21...4adf4d5. Read the comment docs.

@unakb unakb added the automerge Merge this PR as soon as all checks pass label Nov 6, 2024
@kodiakhq kodiakhq bot merged commit 03b426a into main Nov 6, 2024
22 of 23 checks passed
@kodiakhq kodiakhq bot deleted the j-s/fix-migration branch November 6, 2024 14:29
robertaandersen pushed a commit that referenced this pull request Nov 11, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
jonnigs pushed a commit that referenced this pull request Nov 12, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants