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

1254 remove attempts fks #1453

Closed
wants to merge 5 commits into from
Closed

1254 remove attempts fks #1453

wants to merge 5 commits into from

Conversation

rorymckinley
Copy link
Collaborator

@rorymckinley rorymckinley commented Nov 23, 2023

Notes for the reviewer

Removes the FK constraint between attempt_runs & attempts as well as the FK between log_lines and attempts. I added functionality to Attempts to replicate the ON DELETE CASCADE behaviour lost as a result of removing the FK.

I also simplified the tests in AccountsTest and QueueTest as much of what they were testing is now encapsulated in he methods added to Attempts and so the detailed tests now live in AttemptsTest (sorry, makes for a bit of a messy diff - happy to talk through the changes).

Note: I could not test the rollback behaviour for Attempts.delete_for_user as I could not find a way to trigger a rollback from a test. Open to any suggestions as to how I can improve the situation.

I added mocking so that I could test the response when there is an error.

Related issue

Fixes #

Review checklist

  • I have performed a self-review of my code
  • I have verified that all appropriate authorization policies have been implemented and tested
  • If needed, I have updated the changelog
  • Product has QA'd this feature

Copy link

codecov bot commented Nov 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a115e13) 87.50% compared to head (8c6dbee) 87.58%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1453      +/-   ##
==========================================
+ Coverage   87.50%   87.58%   +0.07%     
==========================================
  Files         214      214              
  Lines        6346     6370      +24     
==========================================
+ Hits         5553     5579      +26     
+ Misses        793      791       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rorymckinley
Copy link
Collaborator Author

Please note: Should this PR be reactivated, there are some code changes that need to be made.

The biggest one is to remove all the plumbing added for Mox and use https://hex.pm/packages/mock instead.

There are also some changes required when pattern matching against response from Repo.transaction - see file-level comments for more detail.


case result do
{:ok, %{user: deleted_user}} -> {:ok, deleted_user}
{:error, _, changeset} -> {:error, changeset}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Match against all the elements of the Ecto.Multi error response tuple:

{:error, _failed_operation, changeset, _changes_so_far} -> {:error, changeset}


case result do
{:ok, %{attempt: modified_attempt}} -> {:ok, modified_attempt}
{:error, _, changeset} -> {:error, changeset}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Match against all the elements of the Ecto.Multi error response tuple:

{:error, _failed_operation, changeset, _changes_so_far} -> {:error, changeset}


case result do
{:ok, %{attempts: deleted_attempts}} -> {:ok, deleted_attempts}
{:error, _, changeset} -> {:error, changeset}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Match against all the elements of the Ecto.Multi error response tuple:

{:error, _failed_operation, changeset, _changes_so_far} -> {:error, changeset}

@taylordowns2000
Copy link
Member

@rorymckinley , should this still be in "draft mode" or is it ready for review and merge?

@stuartc stuartc closed this May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants