[chore] Tidy up previous interaction policy migrations (#4171)

This pull request tidies up some previous migrations by making sure there's a proper snapshot in the migrations folder of what interaction policies looked like at the time the migration was written, rather than using the moving target `internal/gtsmodel`.

Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4171
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Co-committed-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
tobi 2025-05-12 16:22:45 +00:00 committed by kim
commit 3fedff3a5a
9 changed files with 451 additions and 43 deletions

View file

@ -22,8 +22,8 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/log"
oldmodel "code.superseriousbusiness.org/gotosocial/internal/db/bundb/migrations/20240620074530_interaction_policy"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
newmodel "code.superseriousbusiness.org/gotosocial/internal/db/bundb/migrations/20240620074530_interaction_policy/new"
oldmodel "code.superseriousbusiness.org/gotosocial/internal/db/bundb/migrations/20240620074530_interaction_policy/old"
"github.com/uptrace/bun"
)
@ -161,49 +161,45 @@ func init() {
return err
}
// Get the mapping of old enum string values to new integer values.
visibilityMapping := visibilityEnumMapping[oldmodel.Visibility]()
// For each status found in this way, update
// to new version of interaction policy.
for _, oldStatus := range oldStatuses {
// Start with default policy for this visibility.
v := visibilityMapping[oldStatus.Visibility]
policy := gtsmodel.DefaultInteractionPolicyFor(v)
policy := newmodel.DefaultInteractionPolicyFor(newmodel.Visibility(oldStatus.Visibility))
if !*oldStatus.Likeable {
// Only author can like.
policy.CanLike = gtsmodel.PolicyRules{
Always: gtsmodel.PolicyValues{
gtsmodel.PolicyValueAuthor,
policy.CanLike = newmodel.PolicyRules{
Always: newmodel.PolicyValues{
newmodel.PolicyValueAuthor,
},
WithApproval: make(gtsmodel.PolicyValues, 0),
WithApproval: make(newmodel.PolicyValues, 0),
}
}
if !*oldStatus.Replyable {
// Only author + mentioned can Reply.
policy.CanReply = gtsmodel.PolicyRules{
Always: gtsmodel.PolicyValues{
gtsmodel.PolicyValueAuthor,
gtsmodel.PolicyValueMentioned,
policy.CanReply = newmodel.PolicyRules{
Always: newmodel.PolicyValues{
newmodel.PolicyValueAuthor,
newmodel.PolicyValueMentioned,
},
WithApproval: make(gtsmodel.PolicyValues, 0),
WithApproval: make(newmodel.PolicyValues, 0),
}
}
if !*oldStatus.Boostable {
// Only author can Announce.
policy.CanAnnounce = gtsmodel.PolicyRules{
Always: gtsmodel.PolicyValues{
gtsmodel.PolicyValueAuthor,
policy.CanAnnounce = newmodel.PolicyRules{
Always: newmodel.PolicyValues{
newmodel.PolicyValueAuthor,
},
WithApproval: make(gtsmodel.PolicyValues, 0),
WithApproval: make(newmodel.PolicyValues, 0),
}
}
// Update status with the new interaction policy.
newStatus := &gtsmodel.Status{
newStatus := &newmodel.Status{
ID: oldStatus.ID,
InteractionPolicy: policy,
}