There should be a unique on your
Environment table on
(organization_id, name). If that is not in place, then you’ll likely have similar issues to the previous thread.
Fixing this is a lot more complex. For each
organization_id, name combo, you’ll need to select the
min(id) as the
Environment you want to keep. Then, for any related tables, you’ll need to update the
environment_id for the environments you want to remove with the correct one (and when there are duplicate rows, remove the duplicates).
There are a lot of tables to do:
- sentry_groupenvironment (if you have a lot of sentry_groupedmessage rows this will be huge).
There are probably more. This isn’t something we’ve ever really had to do, and I’m not sure how your database ended up in this state. It’s possible there will be other side effects to repairing this data, it’s a little hard to predict since we don’t typically do this kind of fixing.
An alternative here is to just remove the duplicate
Environment rows via
sentry shell, and let Django cascade delete all of the duplicates. This will result in data loss on the related tables, but if events are coming in then this data should refill over time. This is a lot easier, but again, hard to predict the side effects of doing something like this.
That’s about all I can offer in terms of advice here. If you have any other questions about this process let me know.