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

Update docs on how to delete tables and columns #11897

Merged
merged 12 commits into from
Nov 22, 2024

Conversation

wedamija
Copy link
Member

This uses the new operations from
getsentry/sentry#81063
getsentry/sentry#81098

@wedamija wedamija requested review from a team November 21, 2024 01:58
Copy link

vercel bot commented Nov 21, 2024

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

Name Status Preview Comments Updated (UTC)
develop-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 22, 2024 7:41pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
changelog ⬜️ Ignored (Inspect) Visit Preview Nov 22, 2024 7:41pm
sentry-docs ⬜️ Ignored (Inspect) Visit Preview Nov 22, 2024 7:41pm

- If the column is a foreign key, remove the database level foreign key constraint it by setting `db_constraint=False`.
- Remove the column and in the generated migration use `SafeRemoveField(..., deletion_action=DeletionAction.MOVE_TO_PENDING)` to replace `RemoveField(...)`. This only marks the state for the column as removed.
- Combine these migrations together to save making multiple deploys
- Deploy. It's important that all previous prs are in production before we remove the actual column from the table.
Copy link
Member

Choose a reason for hiding this comment

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

Should we call this out even more explicitly, maybe a <Note> type thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if it's necessary, people should just be following these steps in order, and we've had the docs like this for a while

- Remove the column from the model, but in the migration make sure we only mark the state as removed.
- Deploy.
- Finally, create a migration that deletes the column.
- (Optional, but ideal) Make a PR to remove all uses of the column in the codebase in a separate PR. This mostly helps with code cleanliness. This should be merged ahead of the migration prs, but we don't need to worry about whether it is deployed first.
Copy link
Member

@evanpurkhiser evanpurkhiser Nov 22, 2024

Choose a reason for hiding this comment

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

I'm slightly confused about the optionality of this, is it just optional that it's a separate PR. It kind of makes it sound like we don't need to remove all the uses of the column, we definitely do.

I actually wouldn't mind if this just was the prescribed flow and remove the note about optionality.

Suggested change
- (Optional, but ideal) Make a PR to remove all uses of the column in the codebase in a separate PR. This mostly helps with code cleanliness. This should be merged ahead of the migration prs, but we don't need to worry about whether it is deployed first.
- Make a PR to remove all uses of the column in the codebase in a separate PR. This mostly helps with code cleanliness. This should be merged ahead of the migration prs, but we don't need to worry about whether it is deployed first.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I think I agree. The process is flexible for me, because maybe there are very few uses and you want to just do those in the first pr, but probably better to just be prescriptive

]
```

Using `SafeRemoveField` allows us to remove all the state related to the column, but defer deleting it until a later migration. So now, we can combine the migration to remove the constraints and delete the column state together like so
Copy link
Member

Choose a reason for hiding this comment

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

It's a little confusing here that the next codeblock we're saying "That second migration you just made, throw that one away, we can combine them into the first"

We do need to describe both, since in the case where there's no alter needed for removing null or FKs, we just want the safe remove, but I feel like we should tweak this a bit to make it more clear that that's whats happening here

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it'd help to just post the two migrations necessary first, then write the steps to get to that state after?

Copy link
Member

Choose a reason for hiding this comment

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

I think that would make sense

Copy link
Member Author

Choose a reason for hiding this comment

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

@evanpurkhiser I updated the docs for deleting a model. Let me know if it's an improvement, and then I'll update the column docs too

@wedamija wedamija force-pushed the danf/migrations-update-table-col-deletion branch from 12d27f4 to d9c9501 Compare November 22, 2024 18:02
@wedamija wedamija enabled auto-merge (squash) November 22, 2024 19:39
@wedamija wedamija merged commit db22cfe into master Nov 22, 2024
10 checks passed
@wedamija wedamija deleted the danf/migrations-update-table-col-deletion branch November 22, 2024 19:41
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.

3 participants