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 Manual Migration Feature #3220

Merged
merged 17 commits into from
May 17, 2023
Merged

Conversation

ThomasLaPiana
Copy link
Contributor

@ThomasLaPiana ThomasLaPiana commented May 4, 2023

Closes #3093

Code Changes

  • add a database setting for automigrate
  • rename init to migrate when referring to the database migration steps, since that feels more accurate and less surprising to me
  • add a deprecation label on fides db init and point people to fides db migrate
  • add a migrate CLI command
  • check for the automigrate config value when doing migrations
  • do some code reorganization to cleanup main.py and move some of the verbose setup to app_setup.py

Steps to Confirm

  • run nox -s teardown -- volumes to clear the database
  • add automigrate = false to the fides.toml in the [database] section
  • run nox -s dev and see that it doesn't run the database migrations and subsequently fails startup
  • remove the line in fides.toml that disables auto-migrations
  • run nox -s dev again and see that everything works (it will also log an INFO statement that migrations are being run)
  • spin everything down and re-add automigrate = false
  • run nox -s dev again and see that it doesn't run migrations, as evidenced by a log INFO stating that migrations are being skipped and lack of migration logging

Pre-Merge Checklist

Description Of Changes

Add the ability for users to turn off auto-migrations. Also rename init to migrate everywhere since it makes more sense (in my opinion) and is used for more than just initializing.

Breaking Changes

The CLI won't see any breaks here, as the init command has been deprecated instead of removed.

However, the db/<action> endpoint has been broken, as it no longer accepts init. This is reflected in the autogenerated documentation though since it uses a proper Enum for the actions.

@ThomasLaPiana ThomasLaPiana self-assigned this May 4, 2023
@cypress
Copy link

cypress bot commented May 4, 2023

Passing run #1990 ↗︎

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 d6b3275 into 87dc86a...
Project: fides Commit: 26f0417195 ℹ️
Status: Passed Duration: 00:46 💡
Started: May 16, 2023 6:51 AM Ended: May 16, 2023 6:52 AM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@codecov
Copy link

codecov bot commented May 4, 2023

Codecov Report

Patch coverage: 81.45% and project coverage change: -0.07 ⚠️

Comparison is base (ad8fda3) 86.95% compared to head (d6b3275) 86.89%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3220      +/-   ##
==========================================
- Coverage   86.95%   86.89%   -0.07%     
==========================================
  Files         307      308       +1     
  Lines       18460    18525      +65     
  Branches     2407     2420      +13     
==========================================
+ Hits        16052    16097      +45     
- Misses       1970     1988      +18     
- Partials      438      440       +2     
Impacted Files Coverage Δ
src/fides/api/app_setup.py 77.65% <77.65%> (ø)
src/fides/api/main.py 82.35% <87.50%> (+3.21%) ⬆️
src/fides/api/ctl/database/database.py 85.91% <100.00%> (ø)
src/fides/api/ctl/routes/admin.py 95.83% <100.00%> (ø)
...ops/service/privacy_request/email_batch_service.py 88.33% <100.00%> (+0.19%) ⬆️
src/fides/cli/commands/db.py 78.78% <100.00%> (-2.70%) ⬇️
src/fides/core/config/database_settings.py 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ThomasLaPiana ThomasLaPiana marked this pull request as ready for review May 11, 2023 08:16
@ThomasLaPiana
Copy link
Contributor Author

@pattisdr This is ready for your review/opinions! Sorry it took so long for me to circle back and put the finishing touches on it

Honestly I'm still iffy on the implementation/UX, given the caveat that it needs to be true on the first startup of a webserver instance. I think given that this will primarily be for development purposes it should be ok though 🙂

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.

this is a nice addition, I think it's fine if it needs to be true on startup. The main thing I thought would be helpful here is for when you're trying to figure out a custom migration and to keep it from auto-migrating on you all the time.

src/fides/api/app_setup.py Show resolved Hide resolved
src/fides/api/app_setup.py Show resolved Hide resolved
src/fides/api/app_setup.py Show resolved Hide resolved
src/fides/api/app_setup.py Outdated Show resolved Hide resolved
src/fides/api/main.py Outdated Show resolved Hide resolved
@ThomasLaPiana
Copy link
Contributor Author

@pattisdr Thank you for the great catches here!

Addressed the comments, ready for another review 🙂

src/fides/api/main.py Outdated Show resolved Hide resolved
@ThomasLaPiana
Copy link
Contributor Author

@pattisdr tossing back to you!

Lmk if there are any big issues here, otherwise I'd prefer to get this merged and iterate

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.

@ThomasLaPiana ThomasLaPiana merged commit c5b8245 into main May 17, 2023
@ThomasLaPiana ThomasLaPiana deleted the ThomasLaPiana-manual-migration-feature branch May 17, 2023 02:47
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.

Move migrations to a CLI command/API endpoint instead of happening automatically
2 participants