[chore] migration to update statuses.thread_id to be notnull (#4160)

# Description

This is quite a complex database migration that updates the `statuses.thread_id` column to be notnull, in order that statuses always be threaded, which will be useful in various pieces of upcoming work. This is unfortunately a migration that acts over the entire statuses table, and is quite complex in order to ensure that all existing statuses get correctly threaded together, and where possible fix any issues of statuses in the same thread having incorrect thread_ids.

TODO:
- ~~update testrig models to all be threaded~~
- ~~update code to ensure thread_id is always set~~
- ~~run on **a copy** of an sqlite production database~~
- ~~run on **a copy** of a postgres production database~~

## Checklist

- [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md).
- [x] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have not leveraged AI to create the proposed changes.
- [x] I/we have performed a self-review of added code.
- [x] I/we have written code that is legible and maintainable by others.
- [x] I/we have commented the added code, particularly in hard-to-understand areas.
- [ ] I/we have made any necessary changes to documentation.
- [x] I/we have added tests that cover new code.
- [x] I/we have run tests and they pass locally with the changes.
- [x] I/we have run `go fmt ./...` and `golangci-lint run`.

Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4160
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
kim 2025-05-26 15:33:42 +02:00 committed by tobi
commit 311d9a1697
19 changed files with 1660 additions and 386 deletions

View file

@ -2154,6 +2154,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
AccountID: "01F8MH17FWEB39HZJ76B6VXSKF",
BoostOfID: "01F8MHAMCHF6Y650WCRSCP4WMY",
BoostOfAccountID: "01F8MH1H7YV1Z7D2C8K2730QBF",
ThreadID: "01JV7NMMYX2Y38ZP3Y9SYJWT36",
Visibility: gtsmodel.VisibilityPublic,
Sensitive: util.Ptr(false),
CreatedWithApplicationID: "01F8MGXQRHYF5QPMTMXP78QC2F",
@ -2312,6 +2313,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(true),
AccountURI: "http://localhost:8080/users/the_mighty_zork",
AccountID: "01F8MH1H7YV1Z7D2C8K2730QBF",
ThreadID: "01JV7PB3BPGFR13Q9B3XD4DJ5W",
Visibility: gtsmodel.VisibilityFollowersOnly,
Sensitive: util.Ptr(false),
Language: "en",
@ -2378,6 +2380,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(true),
AccountURI: "http://localhost:8080/users/the_mighty_zork",
AccountID: "01F8MH1H7YV1Z7D2C8K2730QBF",
ThreadID: "01JV7NT07NPSJQC703A4D0FK49",
EditIDs: []string{"01JDPZCZ2Y9KSGZW0R7ZG8T8Y2", "01JDPZDADMD1T9HKF94RECF7PP"},
Visibility: gtsmodel.VisibilityPublic,
Sensitive: util.Ptr(false),
@ -2581,6 +2584,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(true),
AccountURI: "http://localhost:8080/users/1happyturtle",
AccountID: "01F8MH5NBDF2MV7CTC4Q5128HF",
ThreadID: "01JV7NVEBG7Q27WM66SPMBN3Q5",
Visibility: gtsmodel.VisibilityPublic,
Sensitive: util.Ptr(false),
Language: "en",
@ -2604,6 +2608,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(true),
AccountURI: "http://localhost:8080/users/the_mighty_zork",
AccountID: "01F8MH5NBDF2MV7CTC4Q5128HF",
ThreadID: "01JV7NW0CD8Q8EWSF1RPC0AZXT",
EditIDs: []string{"01JDPZPBXAX0M02YSEPB21KX4R", "01JDPZPJHKP7E3M0YQXEXPS1YT", "01JDPZPY3F85Y7B78ETRXEMWD9"},
Visibility: gtsmodel.VisibilityPublic,
Sensitive: util.Ptr(false),
@ -2629,6 +2634,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(true),
AccountURI: "http://localhost:8080/users/media_mogul",
AccountID: "01JPCMD83Y4WR901094YES3QC5",
ThreadID: "01JV7NXDB7Z6YAFX8ZDKP9C20Y",
Visibility: gtsmodel.VisibilityUnlocked,
Sensitive: util.Ptr(false),
Language: "en",
@ -2653,6 +2659,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(true),
AccountURI: "http://localhost:8080/users/media_mogul",
AccountID: "01JPCMD83Y4WR901094YES3QC5",
ThreadID: "01JV7NXSGST4TYA3SAPADQ04JR",
Visibility: gtsmodel.VisibilityUnlocked,
Sensitive: util.Ptr(false),
Language: "en",
@ -2670,6 +2677,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(false),
AccountURI: "http://fossbros-anonymous.io/users/foss_satan",
AccountID: "01F8MH5ZK5VRH73AKHQM6Y9VNX",
ThreadID: "01JV7NY908EG95DQPJKTXKHCBW",
Visibility: gtsmodel.VisibilityUnlocked,
Sensitive: util.Ptr(false),
Language: "en",
@ -2687,6 +2695,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(false),
AccountURI: "http://fossbros-anonymous.io/users/foss_satan",
AccountID: "01F8MH5ZK5VRH73AKHQM6Y9VNX",
ThreadID: "01JV7NYTCE3384MC1GRVC9V0K0",
Visibility: gtsmodel.VisibilityUnlocked,
Sensitive: util.Ptr(false),
Language: "en",
@ -2705,6 +2714,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(false),
AccountURI: "http://fossbros-anonymous.io/users/foss_satan",
AccountID: "01F8MH5ZK5VRH73AKHQM6Y9VNX",
ThreadID: "01JV7NZ58GGQSVVZMK6P7EBADM",
Visibility: gtsmodel.VisibilityUnlocked,
Sensitive: util.Ptr(false),
Language: "en",
@ -2725,6 +2735,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Local: util.Ptr(false),
AccountURI: "http://fossbros-anonymous.io/users/foss_satan",
AccountID: "01F8MH5ZK5VRH73AKHQM6Y9VNX",
ThreadID: "01JV7NZWF1J2BVQ7SWMMRBYC58",
EditIDs: []string{"01JDQ07ZZ4FGP13YN8TF63P5A6", "01JDQ08AYQC0G6413VAHA51CV9"},
PollID: "01JDQ0EZ5HM9T4WXRQ5WSVD40J",
Visibility: gtsmodel.VisibilityPublic,
@ -2745,6 +2756,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
AccountURI: "http://example.org/users/Some_User",
MentionIDs: []string{"01HE7XQNMKTVC8MNPCE1JGK4J3"},
AccountID: "01FHMQX3GAABWSM0S2VZEC2SWC",
ThreadID: "01HCWDF2Q4HV5QC161C4TGQ0M3",
InReplyToID: "01F8MH75CBF9JFX4ZAD54N0W0R",
InReplyToAccountID: "01F8MH17FWEB39HZJ76B6VXSKF",
InReplyToURI: "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R",
@ -2985,75 +2997,6 @@ func NewTestThreads() map[string]*gtsmodel.Thread {
}
}
func NewTestThreadToStatus() []*gtsmodel.ThreadToStatus {
return []*gtsmodel.ThreadToStatus{
{
ThreadID: "01HCWDF2Q4HV5QC161C4TGQ0M3",
StatusID: "01F8MH75CBF9JFX4ZAD54N0W0R",
},
{
ThreadID: "01HCWDQ1C7APSEY34B1HFVHVX7",
StatusID: "01F8MHAAY43M6RJ473VQFCVH37",
},
{
ThreadID: "01HCWDKKBWECZJQ93E262N36VN",
StatusID: "01FF25D5Q0DH7CHD57CTRS6WK0",
},
{
ThreadID: "01HCWDKKBWECZJQ93E262N36VN",
StatusID: "01F8MHAMCHF6Y650WCRSCP4WMY",
},
{
ThreadID: "01HCWDVTW3HQWSX66VJQ91Z1RH",
StatusID: "01F8MHAYFKS4KMXF8K5Y1C0KRN",
},
{
ThreadID: "01HCWDY9PDNHDBDBBFTJKJY8XE",
StatusID: "01F8MHBBN8120SYH7D5S050MGK",
},
{
ThreadID: "01HCWE0H2GKH794Q7GDPANH91Q",
StatusID: "01F8MH82FYRXD2RC6108DAJ5HB",
},
{
ThreadID: "01HCWE1ERQSMMVWDD0BE491E2P",
StatusID: "01FCTA44PW9H1TB328S9AQXKDS",
},
{
ThreadID: "01HCWE2Q24FWCZE41AS77SDFRZ",
StatusID: "01F8MHBQCBTDKN6X5VHGMMN4MA",
},
{
ThreadID: "01HCWE3P291Z3NJEJVFPW0K9ZQ",
StatusID: "01F8MHC0H0A7XHTVH5F596ZKBM",
},
{
ThreadID: "01HCWE4P0EW9HBA5WHW97D5YV0",
StatusID: "01F8MHC8VWDRBQR0N1BATDDEM5",
},
{
ThreadID: "01HCWDKKBWECZJQ93E262N36VN",
StatusID: "01FCQSQ667XHJ9AV9T27SJJSX5",
},
{
ThreadID: "01HCWDKKBWECZJQ93E262N36VN",
StatusID: "01J2M1HPFSS54S60Y0KYV23KJE",
},
{
ThreadID: "01HCWE71MGRRDSHBKXFD5DDSWR",
StatusID: "01FN3VJGFH10KR7S2PB0GFJZYG",
},
{
ThreadID: "01HCWE7ZNC2SS4P05WA5QYED23",
StatusID: "01G20ZM733MGN8J344T4ZDDFY1",
},
{
ThreadID: "01HCWE4P0EW9HBA5WHW97D5YV0",
StatusID: "01J5QVB9VC76NPPRQ207GG4DRZ",
},
}
}
// NewTestMentions returns a map of gts model mentions keyed by their name.
func NewTestMentions() map[string]*gtsmodel.Mention {
return map[string]*gtsmodel.Mention{