mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 06:12:45 +00:00
Merge both user API databases into one (#2186)
* Merge user API databases into one * Remove DeviceDatabase from config * Fix tests * Try that again * Clean up keyserver device keys when the devices no longer exist in the user API * Tweak ordering * Fix UserExists flag, device check * Allow including empty entries so we can clean them up * Remove logging
This commit is contained in:
parent
0a7dea4450
commit
153bfbbea5
76 changed files with 727 additions and 899 deletions
35
userapi/storage/postgres/deltas/20200929203058_is_active.go
Normal file
35
userapi/storage/postgres/deltas/20200929203058_is_active.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package deltas
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/pressly/goose"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
)
|
||||
|
||||
func LoadFromGoose() {
|
||||
goose.AddMigration(UpIsActive, DownIsActive)
|
||||
goose.AddMigration(UpAddAccountType, DownAddAccountType)
|
||||
}
|
||||
|
||||
func LoadIsActive(m *sqlutil.Migrations) {
|
||||
m.AddMigration(UpIsActive, DownIsActive)
|
||||
}
|
||||
|
||||
func UpIsActive(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE account_accounts ADD COLUMN IF NOT EXISTS is_deactivated BOOLEAN DEFAULT FALSE;")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DownIsActive(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE account_accounts DROP COLUMN is_deactivated;")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package deltas
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
)
|
||||
|
||||
func LoadLastSeenTSIP(m *sqlutil.Migrations) {
|
||||
m.AddMigration(UpLastSeenTSIP, DownLastSeenTSIP)
|
||||
}
|
||||
|
||||
func UpLastSeenTSIP(tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
ALTER TABLE device_devices ADD COLUMN IF NOT EXISTS last_seen_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM CURRENT_TIMESTAMP)*1000;
|
||||
ALTER TABLE device_devices ADD COLUMN IF NOT EXISTS ip TEXT;
|
||||
ALTER TABLE device_devices ADD COLUMN IF NOT EXISTS user_agent TEXT;`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DownLastSeenTSIP(tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
ALTER TABLE device_devices DROP COLUMN last_seen_ts;
|
||||
ALTER TABLE device_devices DROP COLUMN ip;
|
||||
ALTER TABLE device_devices DROP COLUMN user_agent;`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package deltas
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
)
|
||||
|
||||
func LoadAddAccountType(m *sqlutil.Migrations) {
|
||||
m.AddMigration(UpAddAccountType, DownAddAccountType)
|
||||
}
|
||||
|
||||
func UpAddAccountType(tx *sql.Tx) error {
|
||||
// initially set every account to useraccount, change appservice and guest accounts afterwards
|
||||
// (user = 1, guest = 2, admin = 3, appservice = 4)
|
||||
_, err := tx.Exec(`ALTER TABLE account_accounts ADD COLUMN IF NOT EXISTS account_type SMALLINT NOT NULL DEFAULT 1;
|
||||
UPDATE account_accounts SET account_type = 4 WHERE appservice_id <> '';
|
||||
UPDATE account_accounts SET account_type = 2 WHERE localpart ~ '^[0-9]+$';
|
||||
ALTER TABLE account_accounts ALTER COLUMN account_type DROP DEFAULT;`,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DownAddAccountType(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE account_accounts DROP COLUMN account_type;")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue