2019-08-25 15:29:35 +02:00
|
|
|
package upgrades
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
userProfileTable := `CREATE TABLE mx_user_profile (
|
|
|
|
room_id VARCHAR(255),
|
|
|
|
user_id VARCHAR(255),
|
|
|
|
membership VARCHAR(15) NOT NULL,
|
|
|
|
PRIMARY KEY (room_id, user_id)
|
|
|
|
)`
|
|
|
|
|
|
|
|
roomStateTable := `CREATE TABLE mx_room_state (
|
|
|
|
room_id VARCHAR(255) PRIMARY KEY,
|
|
|
|
power_levels TEXT
|
|
|
|
)`
|
|
|
|
|
|
|
|
registrationsTable := `CREATE TABLE mx_registrations (
|
|
|
|
user_id VARCHAR(255) PRIMARY KEY
|
|
|
|
)`
|
|
|
|
|
2020-03-26 22:36:34 +01:00
|
|
|
upgrades[9] = upgrade{"Move state store to main DB", func(tx *sql.Tx, ctx context) error {
|
2019-08-25 16:25:19 +02:00
|
|
|
if ctx.dialect == Postgres {
|
2019-08-25 15:29:35 +02:00
|
|
|
roomStateTable = strings.Replace(roomStateTable, "TEXT", "JSONB", 1)
|
|
|
|
}
|
|
|
|
|
2019-08-25 18:26:04 +02:00
|
|
|
if _, err := tx.Exec(userProfileTable); err != nil {
|
2019-08-25 15:29:35 +02:00
|
|
|
return err
|
|
|
|
} else if _, err = tx.Exec(roomStateTable); err != nil {
|
|
|
|
return err
|
|
|
|
} else if _, err = tx.Exec(registrationsTable); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}}
|
|
|
|
}
|