mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-02-22 02:44:28 -06:00
Add table migrations
This commit is contained in:
parent
3c5c3ea7fb
commit
a505471c90
|
@ -68,10 +68,10 @@ const selectNewNumericLocalpartSQL = "" +
|
||||||
"SELECT nextval('numeric_username_seq')"
|
"SELECT nextval('numeric_username_seq')"
|
||||||
|
|
||||||
const selectPrivacyPolicySQL = "" +
|
const selectPrivacyPolicySQL = "" +
|
||||||
"SELECT policy_version FROM accounts_accounts WHERE localpart = $1"
|
"SELECT policy_version FROM account_accounts WHERE localpart = $1"
|
||||||
|
|
||||||
const batchSelectPrivacyPolicySQL = "" +
|
const batchSelectPrivacyPolicySQL = "" +
|
||||||
"SELECT localpart FROM accounts_accounts WHERE policy_version IS NULL or policy_version <> $1"
|
"SELECT localpart FROM account_accounts WHERE policy_version IS NULL or policy_version <> $1"
|
||||||
|
|
||||||
type accountsStatements struct {
|
type accountsStatements struct {
|
||||||
insertAccountStmt *sql.Stmt
|
insertAccountStmt *sql.Stmt
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
func LoadFromGoose() {
|
func LoadFromGoose() {
|
||||||
goose.AddMigration(UpIsActive, DownIsActive)
|
goose.AddMigration(UpIsActive, DownIsActive)
|
||||||
|
goose.AddMigration(UpAddPolicyVersion, DownAddPolicyVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadIsActive(m *sqlutil.Migrations) {
|
func LoadIsActive(m *sqlutil.Migrations) {
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package deltas
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func LoadAddPolicyVersion(m *sqlutil.Migrations) {
|
||||||
|
m.AddMigration(UpAddPolicyVersion, DownAddPolicyVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpAddPolicyVersion(tx *sql.Tx) error {
|
||||||
|
_, err := tx.Exec("ALTER TABLE account_accounts ADD COLUMN IF NOT EXISTS policy_version TEXT;")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DownAddPolicyVersion(tx *sql.Tx) error {
|
||||||
|
_, err := tx.Exec("ALTER TABLE account_accounts DROP COLUMN policy_version;")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -73,6 +73,7 @@ func NewDatabase(dbProperties *config.DatabaseOptions, serverName gomatrixserver
|
||||||
}
|
}
|
||||||
m := sqlutil.NewMigrations()
|
m := sqlutil.NewMigrations()
|
||||||
deltas.LoadIsActive(m)
|
deltas.LoadIsActive(m)
|
||||||
|
deltas.LoadAddPolicyVersion(m)
|
||||||
if err = m.RunDeltas(db, dbProperties); err != nil {
|
if err = m.RunDeltas(db, dbProperties); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,10 +66,10 @@ const selectNewNumericLocalpartSQL = "" +
|
||||||
"SELECT COUNT(localpart) FROM account_accounts"
|
"SELECT COUNT(localpart) FROM account_accounts"
|
||||||
|
|
||||||
const selectPrivacyPolicySQL = "" +
|
const selectPrivacyPolicySQL = "" +
|
||||||
"SELECT policy_version FROM accounts_accounts WHERE localpart = $1"
|
"SELECT policy_version FROM account_accounts WHERE localpart = $1"
|
||||||
|
|
||||||
const batchSelectPrivacyPolicySQL = "" +
|
const batchSelectPrivacyPolicySQL = "" +
|
||||||
"SELECT localpart FROM accounts_accounts WHERE policy_version IS NULL or policy_version <> $1"
|
"SELECT localpart FROM account_accounts WHERE policy_version IS NULL or policy_version <> $1"
|
||||||
|
|
||||||
type accountsStatements struct {
|
type accountsStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
func LoadFromGoose() {
|
func LoadFromGoose() {
|
||||||
goose.AddMigration(UpIsActive, DownIsActive)
|
goose.AddMigration(UpIsActive, DownIsActive)
|
||||||
|
goose.AddMigration(UpAddPolicyVersion, DownAddPolicyVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadIsActive(m *sqlutil.Migrations) {
|
func LoadIsActive(m *sqlutil.Migrations) {
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package deltas
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func LoadAddPolicyVersion(m *sqlutil.Migrations) {
|
||||||
|
m.AddMigration(UpAddPolicyVersion, DownAddPolicyVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpAddPolicyVersion(tx *sql.Tx) error {
|
||||||
|
_, err := tx.Exec("ALTER TABLE account_accounts ADD COLUMN policy_version TEXT;")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DownAddPolicyVersion(tx *sql.Tx) error {
|
||||||
|
_, err := tx.Exec("ALTER TABLE account_accounts DROP COLUMN policy_version;")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -77,6 +77,7 @@ func NewDatabase(dbProperties *config.DatabaseOptions, serverName gomatrixserver
|
||||||
}
|
}
|
||||||
m := sqlutil.NewMigrations()
|
m := sqlutil.NewMigrations()
|
||||||
deltas.LoadIsActive(m)
|
deltas.LoadIsActive(m)
|
||||||
|
deltas.LoadAddPolicyVersion(m)
|
||||||
if err = m.RunDeltas(db, dbProperties); err != nil {
|
if err = m.RunDeltas(db, dbProperties); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue