mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-11-17 23:43:10 +01:00
Fix state store migration
This commit is contained in:
parent
0b6f14460d
commit
3a9642386c
1 changed files with 8 additions and 4 deletions
|
@ -9,7 +9,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"maunium.net/go/mautrix"
|
"maunium.net/go/mautrix"
|
||||||
"maunium.net/go/mautrix-appservice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -47,7 +46,7 @@ func init() {
|
||||||
return executeBatch(tx, valueStrings, values...)
|
return executeBatch(tx, valueStrings, values...)
|
||||||
}
|
}
|
||||||
|
|
||||||
migrateMemberships := func(tx *sql.Tx, rooms map[string]map[string]mautrix.Member) error {
|
migrateMemberships := func(tx *sql.Tx, rooms map[string]map[string]mautrix.Membership) error {
|
||||||
for roomID, members := range rooms {
|
for roomID, members := range rooms {
|
||||||
if len(members) == 0 {
|
if len(members) == 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -106,13 +105,18 @@ func init() {
|
||||||
user_id VARCHAR(255) PRIMARY KEY
|
user_id VARCHAR(255) PRIMARY KEY
|
||||||
)`
|
)`
|
||||||
|
|
||||||
upgrades[9] = upgrade{"Move state store to main DB", func(tx *sql.Tx, ctx context) error {
|
type TempStateStore struct {
|
||||||
store := appservice.NewBasicStateStore().(*appservice.BasicStateStore)
|
Registrations map[string]bool `json:"registrations"`
|
||||||
|
Members map[string]map[string]mautrix.Membership `json:"memberships"`
|
||||||
|
PowerLevels map[string]*mautrix.PowerLevels `json:"power_levels"`
|
||||||
|
}
|
||||||
|
|
||||||
|
upgrades[9] = upgrade{"Move state store to main DB", func(tx *sql.Tx, ctx context) error {
|
||||||
if ctx.dialect == Postgres {
|
if ctx.dialect == Postgres {
|
||||||
roomStateTable = strings.Replace(roomStateTable, "TEXT", "JSONB", 1)
|
roomStateTable = strings.Replace(roomStateTable, "TEXT", "JSONB", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var store TempStateStore
|
||||||
if _, err := tx.Exec(userProfileTable); err != nil {
|
if _, err := tx.Exec(userProfileTable); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if _, err = tx.Exec(roomStateTable); err != nil {
|
} else if _, err = tx.Exec(roomStateTable); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue