From 661ee4408e98076e328a5a616414ebb474da49dc Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 19 Jul 2024 14:09:42 +0300 Subject: [PATCH] legacymigrate: move to mautrix-go --- cmd/mautrix-slack/legacymigrate.go | 72 ----------------------------- cmd/mautrix-slack/legacymigrate.sql | 2 - cmd/mautrix-slack/main.go | 1 - go.mod | 2 +- go.sum | 4 +- pkg/connector/connector.go | 7 --- 6 files changed, 3 insertions(+), 85 deletions(-) diff --git a/cmd/mautrix-slack/legacymigrate.go b/cmd/mautrix-slack/legacymigrate.go index 23bafdd..4e71c85 100644 --- a/cmd/mautrix-slack/legacymigrate.go +++ b/cmd/mautrix-slack/legacymigrate.go @@ -17,16 +17,7 @@ package main import ( - "context" _ "embed" - "fmt" - - "github.com/rs/zerolog" - "maunium.net/go/mautrix/appservice" - "maunium.net/go/mautrix/bridgev2/database" - "maunium.net/go/mautrix/bridgev2/matrix" - "maunium.net/go/mautrix/event" - "maunium.net/go/mautrix/id" ) const legacyMigrateRenameTables = ` @@ -45,66 +36,3 @@ ALTER TABLE emoji RENAME TO emoji_old; //go:embed legacymigrate.sql var legacyMigrateCopyData string - -func postMigrate(ctx context.Context) error { - wasMigrated, err := m.DB.TableExists(ctx, "database_was_migrated") - if err != nil { - return fmt.Errorf("failed to check if database_was_migrated table exists: %w", err) - } else if !wasMigrated { - return nil - } - zerolog.Ctx(ctx).Info().Msg("Doing post-migration updates to Matrix rooms") - - portals, err := m.Bridge.GetAllPortalsWithMXID(ctx) - if err != nil { - return fmt.Errorf("failed to get all portals: %w", err) - } - for _, portal := range portals { - switch portal.RoomType { - case database.RoomTypeDM: - otherUserID := portal.OtherUserID - if otherUserID == "" { - zerolog.Ctx(ctx).Warn().Msg("DM portal has no other user ID") - } else { - ghost, err := m.Bridge.GetGhostByID(ctx, otherUserID) - if err != nil { - return fmt.Errorf("failed to get ghost for %s: %w", otherUserID, err) - } - mx := ghost.Intent.(*matrix.ASIntent).Matrix - err = m.Matrix.Bot.EnsureJoined(ctx, portal.MXID, appservice.EnsureJoinedParams{ - BotOverride: mx.Client, - }) - if err != nil { - zerolog.Ctx(ctx).Warn().Err(err).Stringer("room_id", portal.MXID).Msg("Failed to ensure bot is joined to DM") - } - pls, err := mx.PowerLevels(ctx, portal.MXID) - if err != nil { - zerolog.Ctx(ctx).Warn().Err(err).Stringer("room_id", portal.MXID).Msg("Failed to get power levels in room") - } else { - userLevel := pls.GetUserLevel(mx.UserID) - pls.EnsureUserLevel(m.Matrix.Bot.UserID, userLevel) - if userLevel > 50 { - pls.SetUserLevel(mx.UserID, 50) - } - _, err = mx.SetPowerLevels(ctx, portal.MXID, pls) - if err != nil { - zerolog.Ctx(ctx).Warn().Err(err).Stringer("room_id", portal.MXID).Msg("Failed to set power levels") - } - } - } - } - _, err = m.Matrix.Bot.SendStateEvent(ctx, portal.MXID, event.StateElementFunctionalMembers, "", &event.ElementFunctionalMembersContent{ - ServiceMembers: []id.UserID{m.Matrix.Bot.UserID}, - }) - if err != nil { - zerolog.Ctx(ctx).Warn().Err(err).Stringer("room_id", portal.MXID).Msg("Failed to set service members") - } - } - - _, err = m.DB.Exec(ctx, "DROP TABLE database_was_migrated") - if err != nil { - return fmt.Errorf("failed to drop database_was_migrated table: %w", err) - } - zerolog.Ctx(ctx).Info().Msg("Post-migration updates complete") - return nil -} diff --git a/cmd/mautrix-slack/legacymigrate.sql b/cmd/mautrix-slack/legacymigrate.sql index e659396..2a2a945 100644 --- a/cmd/mautrix-slack/legacymigrate.sql +++ b/cmd/mautrix-slack/legacymigrate.sql @@ -227,5 +227,3 @@ DROP TABLE user_team_old; DROP TABLE puppet_old; DROP TABLE user_old; DROP TABLE emoji_old; - -CREATE TABLE database_was_migrated(); diff --git a/cmd/mautrix-slack/main.go b/cmd/mautrix-slack/main.go index 33bb9ea..9805f32 100644 --- a/cmd/mautrix-slack/main.go +++ b/cmd/mautrix-slack/main.go @@ -47,7 +47,6 @@ func main() { true, ) } - c.HackyStartupHook = postMigrate m.InitVersion(Tag, Commit, BuildTime) m.Run() } diff --git a/go.mod b/go.mod index 1c21adf..f70ebf1 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/yuin/goldmark v1.7.4 go.mau.fi/util v0.6.0 gopkg.in/yaml.v3 v3.0.1 - maunium.net/go/mautrix v0.19.1-0.20240718165923-a4b0b55db29d + maunium.net/go/mautrix v0.19.1-0.20240719110719-b881a7d45511 ) require ( diff --git a/go.sum b/go.sum index e22e9bb..8337b92 100644 --- a/go.sum +++ b/go.sum @@ -73,5 +73,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M= maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA= -maunium.net/go/mautrix v0.19.1-0.20240718165923-a4b0b55db29d h1:/bZZbGY5XcWdt0HjBSdcjIRcHX8uK+v+DZJyQ8q0Mn4= -maunium.net/go/mautrix v0.19.1-0.20240718165923-a4b0b55db29d/go.mod h1:UE+mSQ4sDUuJMbjN0aB9EjQSGgXd48AzMvZ6+QJV1k8= +maunium.net/go/mautrix v0.19.1-0.20240719110719-b881a7d45511 h1:Qbpe6EdaZn4YzNsJTrowWv34afbc1c8OYij58e7Vl70= +maunium.net/go/mautrix v0.19.1-0.20240719110719-b881a7d45511/go.mod h1:UE+mSQ4sDUuJMbjN0aB9EjQSGgXd48AzMvZ6+QJV1k8= diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index a67c197..5817c22 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -30,8 +30,6 @@ type SlackConnector struct { Config Config DB *slackdb.SlackDB MsgConv *msgconv.MessageConverter - - HackyStartupHook func(context.Context) error } var ( @@ -51,11 +49,6 @@ func (s *SlackConnector) SetMaxFileSize(maxSize int64) { } func (s *SlackConnector) Start(ctx context.Context) error { - if s.HackyStartupHook != nil { - if err := s.HackyStartupHook(ctx); err != nil { - return err - } - } return s.DB.Upgrade(ctx) }