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

Add option to downgrade DB as part of /admin/db endpoint #4893

Merged
merged 10 commits into from
May 22, 2024

Conversation

adamsachs
Copy link
Contributor

@adamsachs adamsachs commented May 16, 2024

Closes PROD-2087

Description Of Changes

Adds a downgrade option to our /admin/db endpoint. Allows specifying a migration revision as a revision query param. revision query param can also be used for upgrade command now, if desired - though in practice, that probably won't be needed much.

Also adds the current revision number/name as a field in the /health/database endpoint response, e.g.

{
  "database": "healthy",
  "database_revision": "fc2b2c06e595"
}

See issue description for more context.

Code Changes

  • add downgrade action to path param enum. executes an alembic downgrade against the db
  • add revision optional query param to allow for migration revision name/number to be specified on the endpoint
  • add the current revision number/name as a field in the /health/database endpoint.
  • fix a downgrade migration that was invalid and would break/stop the downgrade if executed

Steps to Confirm

  • run fides server: nox -s dev
  • hit the /api/v1/admin/db/downgrade endpoint (e.g. thru swagger UI) and specify a revision that's lower than the head on main, e.g. 9e83545ed9b6
  • confirm DB is altered as expected and its alembic_version.version_num value is the revision that was specified in the step above

Pre-Merge Checklist

Copy link

vercel bot commented May 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview May 22, 2024 1:46pm

Copy link

cypress bot commented May 16, 2024

Passing run #7853 ↗︎

0 4 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge e775209 into 1373ba0...
Project: fides Commit: 5efa3dabea ℹ️
Status: Passed Duration: 00:34 💡
Started: May 22, 2024 1:56 PM Ended: May 22, 2024 1:56 PM

Review all test suite changes for PR #4893 ↗︎

Copy link
Contributor Author

@adamsachs adamsachs left a comment

Choose a reason for hiding this comment

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

some notes on misc. cleanup changes i made along the way.

@adamsachs adamsachs marked this pull request as ready for review May 16, 2024 12:52
@adamsachs adamsachs self-assigned this May 16, 2024
@adamsachs adamsachs requested review from NevilleS, pattisdr and RobertKeyser and removed request for NevilleS May 16, 2024 12:52
Copy link

codecov bot commented May 16, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 86.72%. Comparing base (1373ba0) to head (e775209).

Files Patch % Lines
src/fides/api/db/database.py 54.54% 8 Missing and 2 partials ⚠️
src/fides/api/api/v1/endpoints/admin.py 60.00% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4893      +/-   ##
==========================================
- Coverage   86.78%   86.72%   -0.06%     
==========================================
  Files         347      347              
  Lines       21102    21121      +19     
  Branches     2762     2765       +3     
==========================================
+ Hits        18313    18317       +4     
- Misses       2303     2315      +12     
- Partials      486      489       +3     

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

Copy link
Contributor

@pattisdr pattisdr left a comment

Choose a reason for hiding this comment

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

i really like exposing the current revision here.

Further comments: https://ethyca.atlassian.net/browse/PROD-2087?focusedCommentId=41060

src/fides/api/db/database.py Outdated Show resolved Hide resolved
src/fides/api/db/database.py Outdated Show resolved Hide resolved
src/fides/api/db/database.py Outdated Show resolved Hide resolved
src/fides/api/api/v1/endpoints/admin.py Show resolved Hide resolved
src/fides/api/api/v1/endpoints/admin.py Outdated Show resolved Hide resolved
src/fides/api/api/v1/endpoints/admin.py Show resolved Hide resolved
src/fides/api/api/v1/endpoints/health.py Outdated Show resolved Hide resolved
@pattisdr
Copy link
Contributor

Reviewing -

Comment on lines +26 to +29
* If there are any database migrations:
* [ ] Ensure that your downrev is up to date with the latest revision on `main`
* [ ] Ensure that your `downgrade()` migration is correct and works
* [ ] If a downgrade migration is not possible for this change, please call this out in the PR description!
Copy link
Contributor

Choose a reason for hiding this comment

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

nice changelog additions 👍

Copy link
Contributor

@pattisdr pattisdr left a comment

Choose a reason for hiding this comment

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

Looks good to me, I especially like the re-org.

There's an outstanding existing issue if we upgrade and it fails, the API returns that it succeeded, but the logs show the failure. I think we should reticket -

@adamsachs
Copy link
Contributor Author

Looks good to me, I especially like the re-org.

There's an outstanding existing issue if we upgrade and it fails, the API returns that it succeeded, but the logs show the failure. I think we should reticket -

ah yes sorry i ignored that because it was already there and i was the slightest bit unsure about how to best handle/got a bit worried about breaking things. i'll create a follow up ticket - thanks for the speedy and helpful review on this!

@adamsachs adamsachs merged commit bb85e07 into main May 22, 2024
41 of 42 checks passed
@adamsachs adamsachs deleted the asachs/PROD-2087 branch May 22, 2024 19:37
@adamsachs
Copy link
Contributor Author

ticketed https://ethyca.atlassian.net/browse/PROD-2118 as a follow up for the upgrade issue you uncovered 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants