-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backup): Support foreign key remapping (#54610)
When importing into a database that is not entirely flushed, sequences and all, we run into a problem: the foriegn keys in the source JSON file will not match the primary keys of the newly `INSERT`ed models we will be importing. This will cause downstream imports that depend on upstream imports to fail. To resolve this, we maintain a `PrimaryKeyMap` of old pks to new pks for every model. As we import models, we take note of their new pks, so that when foreign key references to these models are encountered later on, we can perform a simple replacement. This generally works well enough, but because we have a circular dependency between `Actor` and `Team`, we must take care to do the appropriate set of dance moves to avoid writing `Actor`s with (necessarily) non-existent `Team` references. To test these changes, I've modified all of `test_models` to *not* reset sequences between database uploads. This should ensure that every such test will produce two JSON files with differing pks, which should give us fairly thorough coverage. Issue: getsentry/team-ospo#170 Issue: getsentry/team-ospo#171
- Loading branch information
1 parent
7518d18
commit 11011d4
Showing
8 changed files
with
230 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[ | ||
{ | ||
"model": "sentry.email", | ||
"pk": 34, | ||
"fields": { | ||
"email": "[email protected]", | ||
"date_added": "2023-06-22T00:00:00.123Z" | ||
} | ||
}, | ||
{ | ||
"model": "sentry.user", | ||
"pk": 12, | ||
"fields": { | ||
"password": "pbkdf2_sha256$150000$iEvdIknqYjTr$+QsGn0tfIJ1FZLxQI37mVU1gL2KbL/wqjMtG/dFhsMA=", | ||
"last_login": null, | ||
"username": "[email protected]", | ||
"name": "", | ||
"email": "[email protected]", | ||
"is_staff": true, | ||
"is_active": true, | ||
"is_superuser": true, | ||
"is_managed": false, | ||
"is_sentry_app": null, | ||
"is_password_expired": false, | ||
"last_password_change": "2023-06-22T22:59:57.023Z", | ||
"flags": "0", | ||
"session_nonce": null, | ||
"date_joined": "2023-06-22T22:59:55.488Z", | ||
"last_active": "2023-06-22T22:59:55.489Z", | ||
"avatar_type": 0, | ||
"avatar_url": null | ||
} | ||
}, | ||
{ | ||
"model": "sentry.useremail", | ||
"pk": 56, | ||
"fields": { | ||
"user": 12, | ||
"email": "[email protected]", | ||
"validation_hash": "mCnWesSVvYQcq7qXQ36AZHwosAd6cghE", | ||
"date_hash_added": "2023-06-22T00:00:00.456Z", | ||
"is_verified": false | ||
} | ||
}, | ||
{ | ||
"model": "sentry.userrole", | ||
"pk": 78, | ||
"fields": { | ||
"date_updated": "2023-06-22T23:00:00.123Z", | ||
"date_added": "2023-06-22T22:54:27.960Z", | ||
"name": "Super Admin", | ||
"permissions": "['broadcasts.admin', 'users.admin', 'options.admin']" | ||
} | ||
}, | ||
{ | ||
"model": "sentry.userroleuser", | ||
"pk": 90, | ||
"fields": { | ||
"date_updated": "2023-06-22T23:00:00.123Z", | ||
"date_added": "2023-06-22T22:59:57.000Z", | ||
"user": 12, | ||
"role": 78 | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.