mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-06 13:43:09 -06:00
Set expires_at to tomorrow
This commit is contained in:
parent
25f45012b8
commit
531a557e9d
|
|
@ -17,8 +17,10 @@ package deltas
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadAddExpiresAt(m *sqlutil.Migrations) {
|
func LoadAddExpiresAt(m *sqlutil.Migrations) {
|
||||||
|
|
@ -26,10 +28,14 @@ func LoadAddExpiresAt(m *sqlutil.Migrations) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func upAddexpiresat(tx *sql.Tx) error {
|
func upAddexpiresat(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("ALTER TABLE federationsender_queue_edus ADD COLUMN IF NOT EXISTS expires_at BIGINT DEFAULT NULL;")
|
_, err := tx.Exec("ALTER TABLE federationsender_queue_edus ADD COLUMN IF NOT EXISTS expires_at BIGINT NOT NULL DEFAULT 0;")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to execute upgrade: %w", err)
|
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("UPDATE federationsender_queue_edus SET expires_at = $1", gomatrixserverlib.AsTimestamp(time.Now().Add(time.Hour*24)))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to update queue_edus: %w", err)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,10 @@ package deltas
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadAddExpiresAt(m *sqlutil.Migrations) {
|
func LoadAddExpiresAt(m *sqlutil.Migrations) {
|
||||||
|
|
@ -36,7 +38,7 @@ CREATE TABLE IF NOT EXISTS federationsender_queue_edus (
|
||||||
edu_type TEXT NOT NULL,
|
edu_type TEXT NOT NULL,
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
json_nid BIGINT NOT NULL,
|
json_nid BIGINT NOT NULL,
|
||||||
expires_at BIGINT
|
expires_at BIGINT NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_edus_json_nid_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_edus_json_nid_idx
|
||||||
|
|
@ -49,53 +51,22 @@ CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_edus_json_nid_idx
|
||||||
INSERT
|
INSERT
|
||||||
INTO federationsender_queue_edus (
|
INTO federationsender_queue_edus (
|
||||||
edu_type, server_name, json_nid, expires_at
|
edu_type, server_name, json_nid, expires_at
|
||||||
) SELECT edu_type, server_name, json_nid, null FROM federationsender_queue_edus_old;
|
) SELECT edu_type, server_name, json_nid, 0 FROM federationsender_queue_edus_old;
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to move data to new table: %w", err)
|
return fmt.Errorf("failed to update queue_edus: %w", err)
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("UPDATE federationsender_queue_edus SET expires_at = $1", gomatrixserverlib.AsTimestamp(time.Now().Add(time.Hour*24)))
|
||||||
_, err = tx.Exec("DROP TABLE federationsender_queue_edus_old;")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create new table: %w", err)
|
return fmt.Errorf("failed to update queue_edus: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func downAddexpiresat(tx *sql.Tx) error {
|
func downAddexpiresat(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("ALTER TABLE federationsender_queue_edus RENAME TO federationsender_queue_edus_old;")
|
_, err := tx.Exec("ALTER TABLE federationsender_queue_edus DROP COLUMN expires_at;")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to rename table: %w", err)
|
return fmt.Errorf("failed to rename table: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(`
|
|
||||||
CREATE TABLE IF NOT EXISTS federationsender_queue_edus (
|
|
||||||
edu_type TEXT NOT NULL,
|
|
||||||
server_name TEXT NOT NULL,
|
|
||||||
json_nid BIGINT NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_edus_json_nid_idx
|
|
||||||
ON federationsender_queue_edus (json_nid, server_name);
|
|
||||||
`)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create new table: %w", err)
|
|
||||||
}
|
|
||||||
_, err = tx.Exec(`
|
|
||||||
INSERT
|
|
||||||
INTO federationsender_queue_edus (
|
|
||||||
edu_type, server_name, json_nid
|
|
||||||
) SELECT edu_type, server_name, json_nid FROM federationsender_queue_edus_old;
|
|
||||||
`)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to move data to new table: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = tx.Exec("DROP TABLE federationsender_queue_edus_old;")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create new table: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue