mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-11 08:03:09 -06:00
Use contexts in migrations
This commit is contained in:
parent
6b3072d8ea
commit
59092b345b
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpRemoveRoomsTable(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
DROP TABLE IF EXISTS federationsender_rooms;
|
||||
`)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpRemoveRoomsTable(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
DROP TABLE IF EXISTS federationsender_rooms;
|
||||
`)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -26,16 +26,16 @@ func UpRefactorKeyChanges(ctx context.Context, tx *sql.Tx) error {
|
|||
// the query to SELECT the max log offset fails on new Dendrite instances as log_offset doesn't
|
||||
// exist on that table. Even though we discard the error, the txn is tainted and gets aborted :/
|
||||
var count int
|
||||
_ = tx.QueryRow(`SELECT count(*) FROM keyserver_key_changes`).Scan(&count)
|
||||
_ = tx.QueryRowContext(ctx, `SELECT count(*) FROM keyserver_key_changes`).Scan(&count)
|
||||
if count > 0 {
|
||||
var maxOffset int64
|
||||
_ = tx.QueryRow(`SELECT coalesce(MAX(log_offset), 0) AS offset FROM keyserver_key_changes`).Scan(&maxOffset)
|
||||
if _, err := tx.Exec(fmt.Sprintf(`CREATE SEQUENCE IF NOT EXISTS keyserver_key_changes_seq START %d`, maxOffset)); err != nil {
|
||||
_ = tx.QueryRowContext(ctx, `SELECT coalesce(MAX(log_offset), 0) AS offset FROM keyserver_key_changes`).Scan(&maxOffset)
|
||||
if _, err := tx.ExecContext(ctx, fmt.Sprintf(`CREATE SEQUENCE IF NOT EXISTS keyserver_key_changes_seq START %d`, maxOffset)); err != nil {
|
||||
return fmt.Errorf("failed to CREATE SEQUENCE for key changes, starting at %d: %s", maxOffset, err)
|
||||
}
|
||||
}
|
||||
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
-- make the new table
|
||||
DROP TABLE IF EXISTS keyserver_key_changes;
|
||||
CREATE TABLE IF NOT EXISTS keyserver_key_changes (
|
||||
|
|
@ -51,7 +51,7 @@ func UpRefactorKeyChanges(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
func DownRefactorKeyChanges(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
-- Drop all data and revert back, we can't keep the data as Kafka offsets determine the numbers
|
||||
DROP SEQUENCE IF EXISTS keyserver_key_changes_seq;
|
||||
DROP TABLE IF EXISTS keyserver_key_changes;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpFixCrossSigningSignatureIndexes(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE keyserver_cross_signing_sigs DROP CONSTRAINT keyserver_cross_signing_sigs_pkey;
|
||||
ALTER TABLE keyserver_cross_signing_sigs ADD PRIMARY KEY (origin_user_id, origin_key_id, target_user_id, target_key_id);
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ func UpFixCrossSigningSignatureIndexes(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
func DownFixCrossSigningSignatureIndexes(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE keyserver_cross_signing_sigs DROP CONSTRAINT keyserver_cross_signing_sigs_pkey;
|
||||
ALTER TABLE keyserver_cross_signing_sigs ADD PRIMARY KEY (origin_user_id, target_user_id, target_key_id);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ func UpRefactorKeyChanges(ctx context.Context, tx *sql.Tx) error {
|
|||
// start counting from the last max offset, else 0.
|
||||
var maxOffset int64
|
||||
var userID string
|
||||
_ = tx.QueryRow(`SELECT user_id, MAX(log_offset) FROM keyserver_key_changes GROUP BY user_id`).Scan(&userID, &maxOffset)
|
||||
_ = tx.QueryRowContext(ctx, `SELECT user_id, MAX(log_offset) FROM keyserver_key_changes GROUP BY user_id`).Scan(&userID, &maxOffset)
|
||||
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
-- make the new table
|
||||
DROP TABLE IF EXISTS keyserver_key_changes;
|
||||
CREATE TABLE IF NOT EXISTS keyserver_key_changes (
|
||||
|
|
@ -41,14 +41,14 @@ func UpRefactorKeyChanges(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
// to start counting from maxOffset, insert a row with that value
|
||||
if userID != "" {
|
||||
_, err = tx.Exec(`INSERT INTO keyserver_key_changes(change_id, user_id) VALUES($1, $2)`, maxOffset, userID)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO keyserver_key_changes(change_id, user_id) VALUES($1, $2)`, maxOffset, userID)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DownRefactorKeyChanges(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
-- Drop all data and revert back, we can't keep the data as Kafka offsets determine the numbers
|
||||
DROP TABLE IF EXISTS keyserver_key_changes;
|
||||
CREATE TABLE IF NOT EXISTS keyserver_key_changes (
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpAddForgottenColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`ALTER TABLE roomserver_membership ADD COLUMN IF NOT EXISTS forgotten BOOLEAN NOT NULL DEFAULT false;`)
|
||||
_, err := tx.ExecContext(ctx, `ALTER TABLE roomserver_membership ADD COLUMN IF NOT EXISTS forgotten BOOLEAN NOT NULL DEFAULT false;`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ func UpAddForgottenColumn(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
func DownAddForgottenColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`ALTER TABLE roomserver_membership DROP COLUMN IF EXISTS forgotten;`)
|
||||
_, err := tx.ExecContext(ctx, `ALTER TABLE roomserver_membership DROP COLUMN IF EXISTS forgotten;`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,36 +44,36 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
var snapshotcount int
|
||||
var maxsnapshotid int
|
||||
var maxblockid int
|
||||
if err := tx.QueryRow(`SELECT COUNT(DISTINCT state_snapshot_nid) FROM roomserver_state_snapshots;`).Scan(&snapshotcount); err != nil {
|
||||
return fmt.Errorf("tx.QueryRow.Scan (count snapshots): %w", err)
|
||||
if err := tx.QueryRowContext(ctx, `SELECT COUNT(DISTINCT state_snapshot_nid) FROM roomserver_state_snapshots;`).Scan(&snapshotcount); err != nil {
|
||||
return fmt.Errorf("tx.QueryRowContext.Scan (count snapshots): %w", err)
|
||||
}
|
||||
if err := tx.QueryRow(`SELECT COALESCE(MAX(state_snapshot_nid),0) FROM roomserver_state_snapshots;`).Scan(&maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.QueryRow.Scan (count snapshots): %w", err)
|
||||
if err := tx.QueryRowContext(ctx, `SELECT COALESCE(MAX(state_snapshot_nid),0) FROM roomserver_state_snapshots;`).Scan(&maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.QueryRowContext.Scan (count snapshots): %w", err)
|
||||
}
|
||||
if err := tx.QueryRow(`SELECT COALESCE(MAX(state_block_nid),0) FROM roomserver_state_block;`).Scan(&maxblockid); err != nil {
|
||||
return fmt.Errorf("tx.QueryRow.Scan (count snapshots): %w", err)
|
||||
if err := tx.QueryRowContext(ctx, `SELECT COALESCE(MAX(state_block_nid),0) FROM roomserver_state_block;`).Scan(&maxblockid); err != nil {
|
||||
return fmt.Errorf("tx.QueryRowContext.Scan (count snapshots): %w", err)
|
||||
}
|
||||
maxsnapshotid++
|
||||
maxblockid++
|
||||
|
||||
if _, err := tx.Exec(`ALTER TABLE roomserver_state_block RENAME TO _roomserver_state_block;`); err != nil {
|
||||
return fmt.Errorf("tx.Exec: %w", err)
|
||||
if _, err := tx.ExecContext(ctx, `ALTER TABLE roomserver_state_block RENAME TO _roomserver_state_block;`); err != nil {
|
||||
return fmt.Errorf("tx.ExecContext: %w", err)
|
||||
}
|
||||
if _, err := tx.Exec(`ALTER TABLE roomserver_state_snapshots RENAME TO _roomserver_state_snapshots;`); err != nil {
|
||||
return fmt.Errorf("tx.Exec: %w", err)
|
||||
if _, err := tx.ExecContext(ctx, `ALTER TABLE roomserver_state_snapshots RENAME TO _roomserver_state_snapshots;`); err != nil {
|
||||
return fmt.Errorf("tx.ExecContext: %w", err)
|
||||
}
|
||||
// We create new sequences starting with the maximum state snapshot and block NIDs.
|
||||
// This means that all newly created snapshots and blocks by the migration will have
|
||||
// NIDs higher than these values, so that when we come to update the references to
|
||||
// these NIDs using UPDATE statements, we can guarantee we are only ever updating old
|
||||
// values and not accidentally overwriting new ones.
|
||||
if _, err := tx.Exec(fmt.Sprintf(`CREATE SEQUENCE roomserver_state_block_nid_sequence START WITH %d;`, maxblockid)); err != nil {
|
||||
return fmt.Errorf("tx.Exec: %w", err)
|
||||
if _, err := tx.ExecContext(ctx, fmt.Sprintf(`CREATE SEQUENCE roomserver_state_block_nid_sequence START WITH %d;`, maxblockid)); err != nil {
|
||||
return fmt.Errorf("tx.ExecContext: %w", err)
|
||||
}
|
||||
if _, err := tx.Exec(fmt.Sprintf(`CREATE SEQUENCE roomserver_state_snapshot_nid_sequence START WITH %d;`, maxsnapshotid)); err != nil {
|
||||
return fmt.Errorf("tx.Exec: %w", err)
|
||||
if _, err := tx.ExecContext(ctx, fmt.Sprintf(`CREATE SEQUENCE roomserver_state_snapshot_nid_sequence START WITH %d;`, maxsnapshotid)); err != nil {
|
||||
return fmt.Errorf("tx.ExecContext: %w", err)
|
||||
}
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS roomserver_state_block (
|
||||
state_block_nid bigint PRIMARY KEY DEFAULT nextval('roomserver_state_block_nid_sequence'),
|
||||
state_block_hash BYTEA UNIQUE,
|
||||
|
|
@ -83,7 +83,7 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("tx.Exec (create blocks table): %w", err)
|
||||
}
|
||||
_, err = tx.Exec(`
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS roomserver_state_snapshots (
|
||||
state_snapshot_nid bigint PRIMARY KEY DEFAULT nextval('roomserver_state_snapshot_nid_sequence'),
|
||||
state_snapshot_hash BYTEA UNIQUE,
|
||||
|
|
@ -100,7 +100,7 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
// in question a state snapshot NID of 0 to indicate 'no snapshot'.
|
||||
// If we don't do this, we'll fail the assertions later on which try to ensure we didn't forget
|
||||
// any snapshots.
|
||||
_, err = tx.Exec(
|
||||
_, err = tx.ExecContext(ctx,
|
||||
`UPDATE roomserver_events SET state_snapshot_nid = 0 WHERE event_type_nid = $1 AND event_state_key_nid = $2`,
|
||||
types.MRoomCreateNID, types.EmptyStateKeyNID,
|
||||
)
|
||||
|
|
@ -111,7 +111,7 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
batchsize := 100
|
||||
for batchoffset := 0; batchoffset < snapshotcount; batchoffset += batchsize {
|
||||
var snapshotrows *sql.Rows
|
||||
snapshotrows, err = tx.Query(`
|
||||
snapshotrows, err = tx.QueryContext(ctx, `
|
||||
SELECT
|
||||
state_snapshot_nid,
|
||||
room_nid,
|
||||
|
|
@ -142,7 +142,7 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
state_block_nid;
|
||||
`, batchsize, batchoffset)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx.Query: %w", err)
|
||||
return fmt.Errorf("tx.QueryContext: %w", err)
|
||||
}
|
||||
|
||||
logrus.Warnf("Rewriting snapshots %d-%d of %d...", batchoffset, batchoffset+batchsize, snapshotcount)
|
||||
|
|
@ -179,7 +179,7 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
// fill in bad create snapshots
|
||||
for _, s := range badCreateSnapshots {
|
||||
var createEventNID types.EventNID
|
||||
err = tx.QueryRow(
|
||||
err = tx.QueryRowContext(ctx,
|
||||
`SELECT event_nid FROM roomserver_events WHERE state_snapshot_nid = $1 AND event_type_nid = 1`, s.StateSnapshotNID,
|
||||
).Scan(&createEventNID)
|
||||
if err == sql.ErrNoRows {
|
||||
|
|
@ -204,7 +204,7 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
var blocknid types.StateBlockNID
|
||||
err = tx.QueryRow(`
|
||||
err = tx.QueryRowContext(ctx, `
|
||||
INSERT INTO roomserver_state_block (state_block_hash, event_nids)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (state_block_hash) DO UPDATE SET event_nids=$2
|
||||
|
|
@ -223,7 +223,7 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
var newNID types.StateSnapshotNID
|
||||
err = tx.QueryRow(`
|
||||
err = tx.QueryRowContext(ctx, `
|
||||
INSERT INTO roomserver_state_snapshots (state_snapshot_hash, room_nid, state_block_nids)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (state_snapshot_hash) DO UPDATE SET room_nid=$2
|
||||
|
|
@ -233,12 +233,12 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
return fmt.Errorf("tx.QueryRow.Scan (insert new snapshot): %w", err)
|
||||
}
|
||||
|
||||
if _, err = tx.Exec(`UPDATE roomserver_events SET state_snapshot_nid=$1 WHERE state_snapshot_nid=$2 AND state_snapshot_nid<$3`, newNID, snapshotdata.StateSnapshotNID, maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.Exec (update events): %w", err)
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE roomserver_events SET state_snapshot_nid=$1 WHERE state_snapshot_nid=$2 AND state_snapshot_nid<$3`, newNID, snapshotdata.StateSnapshotNID, maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.ExecContext (update events): %w", err)
|
||||
}
|
||||
|
||||
if _, err = tx.Exec(`UPDATE roomserver_rooms SET state_snapshot_nid=$1 WHERE state_snapshot_nid=$2 AND state_snapshot_nid<$3`, newNID, snapshotdata.StateSnapshotNID, maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.Exec (update rooms): %w", err)
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE roomserver_rooms SET state_snapshot_nid=$1 WHERE state_snapshot_nid=$2 AND state_snapshot_nid<$3`, newNID, snapshotdata.StateSnapshotNID, maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.ExecContext (update rooms): %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -248,13 +248,13 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
// in roomserver_state_snapshots
|
||||
var count int64
|
||||
|
||||
if err = tx.QueryRow(`SELECT COUNT(*) FROM roomserver_events WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid).Scan(&count); err != nil {
|
||||
if err = tx.QueryRowContext(ctx, `SELECT COUNT(*) FROM roomserver_events WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid).Scan(&count); err != nil {
|
||||
return fmt.Errorf("assertion query failed: %s", err)
|
||||
}
|
||||
if count > 0 {
|
||||
var res sql.Result
|
||||
var c int64
|
||||
res, err = tx.Exec(`UPDATE roomserver_events SET state_snapshot_nid = 0 WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid)
|
||||
res, err = tx.ExecContext(ctx, `UPDATE roomserver_events SET state_snapshot_nid = 0 WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return fmt.Errorf("failed to reset invalid state snapshots: %w", err)
|
||||
}
|
||||
|
|
@ -264,13 +264,13 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
return fmt.Errorf("expected to reset %d event(s) but only updated %d event(s)", count, c)
|
||||
}
|
||||
}
|
||||
if err = tx.QueryRow(`SELECT COUNT(*) FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid).Scan(&count); err != nil {
|
||||
if err = tx.QueryRowContext(ctx, `SELECT COUNT(*) FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid).Scan(&count); err != nil {
|
||||
return fmt.Errorf("assertion query failed: %s", err)
|
||||
}
|
||||
if count > 0 {
|
||||
var debugRoomID string
|
||||
var debugSnapNID, debugLastEventNID int64
|
||||
err = tx.QueryRow(
|
||||
err = tx.QueryRowContext(ctx,
|
||||
`SELECT room_id, state_snapshot_nid, last_event_sent_nid FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid,
|
||||
).Scan(&debugRoomID, &debugSnapNID, &debugLastEventNID)
|
||||
if err != nil {
|
||||
|
|
@ -287,13 +287,13 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
return fmt.Errorf("%d rooms exist in roomserver_rooms which have not been converted to a new state_snapshot_nid; this is a bug, please report", count)
|
||||
}
|
||||
|
||||
if _, err = tx.Exec(`
|
||||
if _, err = tx.ExecContext(ctx, `
|
||||
DROP TABLE _roomserver_state_snapshots;
|
||||
DROP SEQUENCE roomserver_state_snapshot_nid_seq;
|
||||
`); err != nil {
|
||||
return fmt.Errorf("tx.Exec (delete old snapshot table): %w", err)
|
||||
}
|
||||
if _, err = tx.Exec(`
|
||||
if _, err = tx.ExecContext(ctx, `
|
||||
DROP TABLE _roomserver_state_block;
|
||||
DROP SEQUENCE roomserver_state_block_nid_seq;
|
||||
`); err != nil {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
|
|
@ -61,7 +60,7 @@ func Open(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, cache c
|
|||
Version: "roomserver: state blocks refactor",
|
||||
Up: deltas.UpStateBlocksRefactor,
|
||||
})
|
||||
if err := m.Up(context.Background()); err != nil {
|
||||
if err := m.Up(base.Context()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpAddForgottenColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(` ALTER TABLE roomserver_membership RENAME TO roomserver_membership_tmp;
|
||||
_, err := tx.ExecContext(ctx, ` ALTER TABLE roomserver_membership RENAME TO roomserver_membership_tmp;
|
||||
CREATE TABLE IF NOT EXISTS roomserver_membership (
|
||||
room_nid INTEGER NOT NULL,
|
||||
target_nid INTEGER NOT NULL,
|
||||
|
|
@ -47,7 +47,7 @@ DROP TABLE roomserver_membership_tmp;`)
|
|||
}
|
||||
|
||||
func DownAddForgottenColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(` ALTER TABLE roomserver_membership RENAME TO roomserver_membership_tmp;
|
||||
_, err := tx.ExecContext(ctx, ` ALTER TABLE roomserver_membership RENAME TO roomserver_membership_tmp;
|
||||
CREATE TABLE IF NOT EXISTS roomserver_membership (
|
||||
room_nid INTEGER NOT NULL,
|
||||
target_nid INTEGER NOT NULL,
|
||||
|
|
|
|||
|
|
@ -33,23 +33,23 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
|
||||
var maxsnapshotid int
|
||||
var maxblockid int
|
||||
if err := tx.QueryRow(`SELECT IFNULL(MAX(state_snapshot_nid),0) FROM roomserver_state_snapshots;`).Scan(&maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.QueryRow.Scan (count snapshots): %w", err)
|
||||
if err := tx.QueryRowContext(ctx, `SELECT IFNULL(MAX(state_snapshot_nid),0) FROM roomserver_state_snapshots;`).Scan(&maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.QueryRowContext.Scan (count snapshots): %w", err)
|
||||
}
|
||||
if err := tx.QueryRow(`SELECT IFNULL(MAX(state_block_nid),0) FROM roomserver_state_block;`).Scan(&maxblockid); err != nil {
|
||||
return fmt.Errorf("tx.QueryRow.Scan (count snapshots): %w", err)
|
||||
if err := tx.QueryRowContext(ctx, `SELECT IFNULL(MAX(state_block_nid),0) FROM roomserver_state_block;`).Scan(&maxblockid); err != nil {
|
||||
return fmt.Errorf("tx.QueryRowContext.Scan (count snapshots): %w", err)
|
||||
}
|
||||
maxsnapshotid++
|
||||
maxblockid++
|
||||
oldMaxSnapshotID := maxsnapshotid
|
||||
|
||||
if _, err := tx.Exec(`ALTER TABLE roomserver_state_block RENAME TO _roomserver_state_block;`); err != nil {
|
||||
return fmt.Errorf("tx.Exec: %w", err)
|
||||
if _, err := tx.ExecContext(ctx, `ALTER TABLE roomserver_state_block RENAME TO _roomserver_state_block;`); err != nil {
|
||||
return fmt.Errorf("tx.ExecContext: %w", err)
|
||||
}
|
||||
if _, err := tx.Exec(`ALTER TABLE roomserver_state_snapshots RENAME TO _roomserver_state_snapshots;`); err != nil {
|
||||
return fmt.Errorf("tx.Exec: %w", err)
|
||||
if _, err := tx.ExecContext(ctx, `ALTER TABLE roomserver_state_snapshots RENAME TO _roomserver_state_snapshots;`); err != nil {
|
||||
return fmt.Errorf("tx.ExecContext: %w", err)
|
||||
}
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS roomserver_state_block (
|
||||
state_block_nid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
state_block_hash BLOB UNIQUE,
|
||||
|
|
@ -57,9 +57,9 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
);
|
||||
`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx.Exec: %w", err)
|
||||
return fmt.Errorf("tx.ExecContext: %w", err)
|
||||
}
|
||||
_, err = tx.Exec(`
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS roomserver_state_snapshots (
|
||||
state_snapshot_nid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
state_snapshot_hash BLOB UNIQUE,
|
||||
|
|
@ -68,11 +68,11 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
);
|
||||
`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx.Exec: %w", err)
|
||||
return fmt.Errorf("tx.ExecContext: %w", err)
|
||||
}
|
||||
snapshotrows, err := tx.Query(`SELECT state_snapshot_nid, room_nid, state_block_nids FROM _roomserver_state_snapshots;`)
|
||||
snapshotrows, err := tx.QueryContext(ctx, `SELECT state_snapshot_nid, room_nid, state_block_nids FROM _roomserver_state_snapshots;`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx.Query: %w", err)
|
||||
return fmt.Errorf("tx.QueryContext: %w", err)
|
||||
}
|
||||
defer internal.CloseAndLogIfError(context.TODO(), snapshotrows, "rows.close() failed")
|
||||
for snapshotrows.Next() {
|
||||
|
|
@ -94,7 +94,7 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
// in question a state snapshot NID of 0 to indicate 'no snapshot'.
|
||||
// If we don't do this, we'll fail the assertions later on which try to ensure we didn't forget
|
||||
// any snapshots.
|
||||
_, err = tx.Exec(
|
||||
_, err = tx.ExecContext(ctx,
|
||||
`UPDATE roomserver_events SET state_snapshot_nid = 0 WHERE event_type_nid = $1 AND event_state_key_nid = $2 AND state_snapshot_nid = $3`,
|
||||
types.MRoomCreateNID, types.EmptyStateKeyNID, snapshot,
|
||||
)
|
||||
|
|
@ -104,9 +104,9 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
for _, block := range blocks {
|
||||
if err = func() error {
|
||||
blockrows, berr := tx.Query(`SELECT event_nid FROM _roomserver_state_block WHERE state_block_nid = $1`, block)
|
||||
blockrows, berr := tx.QueryContext(ctx, `SELECT event_nid FROM _roomserver_state_block WHERE state_block_nid = $1`, block)
|
||||
if berr != nil {
|
||||
return fmt.Errorf("tx.Query (event nids from old block): %w", berr)
|
||||
return fmt.Errorf("tx.QueryContext (event nids from old block): %w", berr)
|
||||
}
|
||||
defer internal.CloseAndLogIfError(context.TODO(), blockrows, "rows.close() failed")
|
||||
events := types.EventNIDs{}
|
||||
|
|
@ -124,14 +124,14 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
var blocknid types.StateBlockNID
|
||||
err = tx.QueryRow(`
|
||||
err = tx.QueryRowContext(ctx, `
|
||||
INSERT INTO roomserver_state_block (state_block_nid, state_block_hash, event_nids)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (state_block_hash) DO UPDATE SET event_nids=$3
|
||||
RETURNING state_block_nid
|
||||
`, maxblockid, events.Hash(), eventjson).Scan(&blocknid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx.QueryRow.Scan (insert new block): %w", err)
|
||||
return fmt.Errorf("tx.QueryRowContext.Scan (insert new block): %w", err)
|
||||
}
|
||||
maxblockid++
|
||||
newblocks = append(newblocks, blocknid)
|
||||
|
|
@ -146,22 +146,22 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
var newsnapshot types.StateSnapshotNID
|
||||
err = tx.QueryRow(`
|
||||
err = tx.QueryRowContext(ctx, `
|
||||
INSERT INTO roomserver_state_snapshots (state_snapshot_nid, state_snapshot_hash, room_nid, state_block_nids)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (state_snapshot_hash) DO UPDATE SET room_nid=$3
|
||||
RETURNING state_snapshot_nid
|
||||
`, maxsnapshotid, newblocks.Hash(), room, newblocksjson).Scan(&newsnapshot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx.QueryRow.Scan (insert new snapshot): %w", err)
|
||||
return fmt.Errorf("tx.QueryRowContext.Scan (insert new snapshot): %w", err)
|
||||
}
|
||||
maxsnapshotid++
|
||||
_, err = tx.Exec(`UPDATE roomserver_events SET state_snapshot_nid=$1 WHERE state_snapshot_nid=$2 AND state_snapshot_nid<$3`, newsnapshot, snapshot, maxsnapshotid)
|
||||
_, err = tx.ExecContext(ctx, `UPDATE roomserver_events SET state_snapshot_nid=$1 WHERE state_snapshot_nid=$2 AND state_snapshot_nid<$3`, newsnapshot, snapshot, maxsnapshotid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx.Exec (update events): %w", err)
|
||||
return fmt.Errorf("tx.ExecContext (update events): %w", err)
|
||||
}
|
||||
if _, err = tx.Exec(`UPDATE roomserver_rooms SET state_snapshot_nid=$1 WHERE state_snapshot_nid=$2 AND state_snapshot_nid<$3`, newsnapshot, snapshot, maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.Exec (update rooms): %w", err)
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE roomserver_rooms SET state_snapshot_nid=$1 WHERE state_snapshot_nid=$2 AND state_snapshot_nid<$3`, newsnapshot, snapshot, maxsnapshotid); err != nil {
|
||||
return fmt.Errorf("tx.ExecContext (update rooms): %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -170,13 +170,13 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
// If we do, this is a problem if Dendrite tries to load the snapshot as it will not exist
|
||||
// in roomserver_state_snapshots
|
||||
var count int64
|
||||
if err = tx.QueryRow(`SELECT COUNT(*) FROM roomserver_events WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, oldMaxSnapshotID).Scan(&count); err != nil {
|
||||
if err = tx.QueryRowContext(ctx, `SELECT COUNT(*) FROM roomserver_events WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, oldMaxSnapshotID).Scan(&count); err != nil {
|
||||
return fmt.Errorf("assertion query failed: %s", err)
|
||||
}
|
||||
if count > 0 {
|
||||
var res sql.Result
|
||||
var c int64
|
||||
res, err = tx.Exec(`UPDATE roomserver_events SET state_snapshot_nid = 0 WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, oldMaxSnapshotID)
|
||||
res, err = tx.ExecContext(ctx, `UPDATE roomserver_events SET state_snapshot_nid = 0 WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, oldMaxSnapshotID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return fmt.Errorf("failed to reset invalid state snapshots: %w", err)
|
||||
}
|
||||
|
|
@ -186,17 +186,17 @@ func UpStateBlocksRefactor(ctx context.Context, tx *sql.Tx) error {
|
|||
return fmt.Errorf("expected to reset %d event(s) but only updated %d event(s)", count, c)
|
||||
}
|
||||
}
|
||||
if err = tx.QueryRow(`SELECT COUNT(*) FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, oldMaxSnapshotID).Scan(&count); err != nil {
|
||||
if err = tx.QueryRowContext(ctx, `SELECT COUNT(*) FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, oldMaxSnapshotID).Scan(&count); err != nil {
|
||||
return fmt.Errorf("assertion query failed: %s", err)
|
||||
}
|
||||
if count > 0 {
|
||||
return fmt.Errorf("%d rooms exist in roomserver_rooms which have not been converted to a new state_snapshot_nid; this is a bug, please report", count)
|
||||
}
|
||||
|
||||
if _, err = tx.Exec(`DROP TABLE _roomserver_state_snapshots;`); err != nil {
|
||||
if _, err = tx.ExecContext(ctx, `DROP TABLE _roomserver_state_snapshots;`); err != nil {
|
||||
return fmt.Errorf("tx.Exec (delete old snapshot table): %w", err)
|
||||
}
|
||||
if _, err = tx.Exec(`DROP TABLE _roomserver_state_block;`); err != nil {
|
||||
if _, err = tx.ExecContext(ctx, `DROP TABLE _roomserver_state_block;`); err != nil {
|
||||
return fmt.Errorf("tx.Exec (delete old block table): %w", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func Open(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, cache c
|
|||
Version: "roomserver: state blocks refactor",
|
||||
Up: deltas.UpStateBlocksRefactor,
|
||||
})
|
||||
if err := m.Up(context.Background()); err != nil {
|
||||
if err := m.Up(base.Context()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpFixSequences(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
-- We need to delete all of the existing receipts because the indexes
|
||||
-- will be wrong, and we'll get primary key violations if we try to
|
||||
-- reuse existing stream IDs from a different sequence.
|
||||
|
|
@ -39,7 +39,7 @@ func UpFixSequences(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
func DownFixSequences(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
-- We need to delete all of the existing receipts because the indexes
|
||||
-- will be wrong, and we'll get primary key violations if we try to
|
||||
-- reuse existing stream IDs from a different sequence.
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpRemoveSendToDeviceSentColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE syncapi_send_to_device
|
||||
DROP COLUMN IF EXISTS sent_by_token;
|
||||
`)
|
||||
|
|
@ -32,7 +32,7 @@ func UpRemoveSendToDeviceSentColumn(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
func DownRemoveSendToDeviceSentColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE syncapi_send_to_device
|
||||
ADD COLUMN IF NOT EXISTS sent_by_token TEXT;
|
||||
`)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpAddHistoryVisibilityColumnOutputRoomEvents(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE syncapi_output_room_events ADD COLUMN IF NOT EXISTS history_visibility SMALLINT NOT NULL DEFAULT 2;
|
||||
UPDATE syncapi_output_room_events SET history_visibility = 4 WHERE type IN ('m.room.message', 'm.room.encrypted');
|
||||
`)
|
||||
|
|
@ -32,7 +32,7 @@ func UpAddHistoryVisibilityColumnOutputRoomEvents(ctx context.Context, tx *sql.T
|
|||
}
|
||||
|
||||
func UpAddHistoryVisibilityColumnCurrentRoomState(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE syncapi_current_room_state ADD COLUMN IF NOT EXISTS history_visibility SMALLINT NOT NULL DEFAULT 2;
|
||||
UPDATE syncapi_current_room_state SET history_visibility = 4 WHERE type IN ('m.room.message', 'm.room.encrypted');
|
||||
`)
|
||||
|
|
@ -43,7 +43,7 @@ func UpAddHistoryVisibilityColumnCurrentRoomState(ctx context.Context, tx *sql.T
|
|||
}
|
||||
|
||||
func DownAddHistoryVisibilityColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE syncapi_output_room_events DROP COLUMN IF EXISTS history_visibility;
|
||||
ALTER TABLE syncapi_current_room_state DROP COLUMN IF EXISTS history_visibility;
|
||||
`)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpFixSequences(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
-- We need to delete all of the existing receipts because the indexes
|
||||
-- will be wrong, and we'll get primary key violations if we try to
|
||||
-- reuse existing stream IDs from a different sequence.
|
||||
|
|
@ -35,7 +35,7 @@ func UpFixSequences(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
func DownFixSequences(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
-- We need to delete all of the existing receipts because the indexes
|
||||
-- will be wrong, and we'll get primary key violations if we try to
|
||||
-- reuse existing stream IDs from a different sequence.
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func UpRemoveSendToDeviceSentColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
CREATE TEMPORARY TABLE syncapi_send_to_device_backup(id, user_id, device_id, content);
|
||||
INSERT INTO syncapi_send_to_device_backup SELECT id, user_id, device_id, content FROM syncapi_send_to_device;
|
||||
DROP TABLE syncapi_send_to_device;
|
||||
|
|
@ -41,7 +41,7 @@ func UpRemoveSendToDeviceSentColumn(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
func DownRemoveSendToDeviceSentColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
CREATE TEMPORARY TABLE syncapi_send_to_device_backup(id, user_id, device_id, content);
|
||||
INSERT INTO syncapi_send_to_device_backup SELECT id, user_id, device_id, content FROM syncapi_send_to_device;
|
||||
DROP TABLE syncapi_send_to_device;
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ import (
|
|||
func UpAddHistoryVisibilityColumnOutputRoomEvents(ctx context.Context, tx *sql.Tx) error {
|
||||
// SQLite doesn't have "if exists", so check if the column exists. If the query doesn't return an error, it already exists.
|
||||
// Required for unit tests, as otherwise a duplicate column error will show up.
|
||||
_, err := tx.Query("SELECT history_visibility FROM syncapi_output_room_events LIMIT 1")
|
||||
_, err := tx.QueryContext(ctx, "SELECT history_visibility FROM syncapi_output_room_events LIMIT 1")
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
_, err = tx.Exec(`
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
ALTER TABLE syncapi_output_room_events ADD COLUMN history_visibility SMALLINT NOT NULL DEFAULT 2;
|
||||
UPDATE syncapi_output_room_events SET history_visibility = 4 WHERE type IN ('m.room.message', 'm.room.encrypted');
|
||||
`)
|
||||
|
|
@ -40,11 +40,11 @@ func UpAddHistoryVisibilityColumnOutputRoomEvents(ctx context.Context, tx *sql.T
|
|||
func UpAddHistoryVisibilityColumnCurrentRoomState(ctx context.Context, tx *sql.Tx) error {
|
||||
// SQLite doesn't have "if exists", so check if the column exists. If the query doesn't return an error, it already exists.
|
||||
// Required for unit tests, as otherwise a duplicate column error will show up.
|
||||
_, err := tx.Query("SELECT history_visibility FROM syncapi_current_room_state LIMIT 1")
|
||||
_, err := tx.QueryContext(ctx, "SELECT history_visibility FROM syncapi_current_room_state LIMIT 1")
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
_, err = tx.Exec(`
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
ALTER TABLE syncapi_current_room_state ADD COLUMN history_visibility SMALLINT NOT NULL DEFAULT 2;
|
||||
UPDATE syncapi_current_room_state SET history_visibility = 4 WHERE type IN ('m.room.message', 'm.room.encrypted');
|
||||
`)
|
||||
|
|
@ -56,23 +56,23 @@ func UpAddHistoryVisibilityColumnCurrentRoomState(ctx context.Context, tx *sql.T
|
|||
|
||||
func DownAddHistoryVisibilityColumn(ctx context.Context, tx *sql.Tx) error {
|
||||
// SQLite doesn't have "if exists", so check if the column exists.
|
||||
_, err := tx.Query("SELECT history_visibility FROM syncapi_output_room_events LIMIT 1")
|
||||
_, err := tx.QueryContext(ctx, "SELECT history_visibility FROM syncapi_output_room_events LIMIT 1")
|
||||
if err != nil {
|
||||
// The column probably doesn't exist
|
||||
return nil
|
||||
}
|
||||
_, err = tx.Exec(`
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
ALTER TABLE syncapi_output_room_events DROP COLUMN history_visibility;
|
||||
`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||
}
|
||||
_, err = tx.Query("SELECT history_visibility FROM syncapi_current_room_state LIMIT 1")
|
||||
_, err = tx.QueryContext(ctx, "SELECT history_visibility FROM syncapi_current_room_state LIMIT 1")
|
||||
if err != nil {
|
||||
// The column probably doesn't exist
|
||||
return nil
|
||||
}
|
||||
_, err = tx.Exec(`
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
ALTER TABLE syncapi_current_room_state DROP COLUMN history_visibility;
|
||||
`)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func UpIsActive(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE account_accounts ADD COLUMN IF NOT EXISTS is_deactivated BOOLEAN DEFAULT FALSE;")
|
||||
_, err := tx.ExecContext(ctx, "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)
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ func UpIsActive(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
func DownIsActive(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE account_accounts DROP COLUMN is_deactivated;")
|
||||
_, err := tx.ExecContext(ctx, "ALTER TABLE account_accounts DROP COLUMN is_deactivated;")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func UpLastSeenTSIP(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
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;`)
|
||||
|
|
@ -18,7 +18,7 @@ ALTER TABLE device_devices ADD COLUMN IF NOT EXISTS user_agent TEXT;`)
|
|||
}
|
||||
|
||||
func DownLastSeenTSIP(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE device_devices DROP COLUMN last_seen_ts;
|
||||
ALTER TABLE device_devices DROP COLUMN ip;
|
||||
ALTER TABLE device_devices DROP COLUMN user_agent;`)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
func UpAddAccountType(ctx context.Context, 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;
|
||||
_, err := tx.ExecContext(ctx, `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;`,
|
||||
|
|
@ -21,7 +21,7 @@ ALTER TABLE account_accounts ALTER COLUMN account_type DROP DEFAULT;`,
|
|||
}
|
||||
|
||||
func DownAddAccountType(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE account_accounts DROP COLUMN account_type;")
|
||||
_, err := tx.ExecContext(ctx, "ALTER TABLE account_accounts DROP COLUMN account_type;")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func UpIsActive(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE account_accounts RENAME TO account_accounts_tmp;
|
||||
CREATE TABLE account_accounts (
|
||||
localpart TEXT NOT NULL PRIMARY KEY,
|
||||
|
|
@ -31,7 +31,7 @@ DROP TABLE account_accounts_tmp;`)
|
|||
}
|
||||
|
||||
func DownIsActive(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE account_accounts RENAME TO account_accounts_tmp;
|
||||
CREATE TABLE account_accounts (
|
||||
localpart TEXT NOT NULL PRIMARY KEY,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func UpLastSeenTSIP(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE device_devices RENAME TO device_devices_tmp;
|
||||
CREATE TABLE device_devices (
|
||||
access_token TEXT PRIMARY KEY,
|
||||
|
|
@ -35,7 +35,7 @@ func UpLastSeenTSIP(ctx context.Context, tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
func DownLastSeenTSIP(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
ALTER TABLE device_devices RENAME TO device_devices_tmp;
|
||||
CREATE TABLE IF NOT EXISTS device_devices (
|
||||
access_token TEXT PRIMARY KEY,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
func UpAddAccountType(ctx context.Context, 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 RENAME TO account_accounts_tmp;
|
||||
_, err := tx.ExecContext(ctx, `ALTER TABLE account_accounts RENAME TO account_accounts_tmp;
|
||||
CREATE TABLE account_accounts (
|
||||
localpart TEXT NOT NULL PRIMARY KEY,
|
||||
created_ts BIGINT NOT NULL,
|
||||
|
|
@ -35,7 +35,7 @@ DROP TABLE account_accounts_tmp;`)
|
|||
}
|
||||
|
||||
func DownAddAccountType(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`ALTER TABLE account_accounts DROP COLUMN account_type;`)
|
||||
_, err := tx.ExecContext(ctx, `ALTER TABLE account_accounts DROP COLUMN account_type;`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute downgrade: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue