2022-03-24 21:14:08 +01:00
|
|
|
package upgrades
|
|
|
|
|
2022-04-06 16:45:45 +02:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
)
|
2022-03-24 21:14:08 +01:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
upgrades[39] = upgrade{"Add backfill queue", func(tx *sql.Tx, ctx context) error {
|
2022-04-06 16:45:45 +02:00
|
|
|
// The queue_id needs to auto-increment every insertion. For SQLite,
|
|
|
|
// INTEGER PRIMARY KEY is an alias for the ROWID, so it will
|
|
|
|
// auto-increment. See https://sqlite.org/lang_createtable.html#rowid
|
|
|
|
// For Postgres, we need to add GENERATED ALWAYS AS IDENTITY for the
|
|
|
|
// same functionality.
|
|
|
|
queueIDColumnTypeModifier := ""
|
|
|
|
if ctx.dialect == Postgres {
|
|
|
|
queueIDColumnTypeModifier = "GENERATED ALWAYS AS IDENTITY"
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := tx.Exec(fmt.Sprintf(`
|
2022-03-24 21:14:08 +01:00
|
|
|
CREATE TABLE backfill_queue (
|
2022-04-06 16:45:45 +02:00
|
|
|
queue_id INTEGER PRIMARY KEY %s,
|
2022-03-24 21:14:08 +01:00
|
|
|
user_mxid TEXT,
|
|
|
|
type INTEGER NOT NULL,
|
|
|
|
priority INTEGER NOT NULL,
|
2022-04-07 17:20:12 +02:00
|
|
|
portal_jid TEXT,
|
|
|
|
portal_receiver TEXT,
|
2022-03-24 21:14:08 +01:00
|
|
|
time_start TIMESTAMP,
|
|
|
|
time_end TIMESTAMP,
|
|
|
|
max_batch_events INTEGER NOT NULL,
|
|
|
|
max_total_events INTEGER,
|
|
|
|
batch_delay INTEGER,
|
2022-04-05 21:12:57 +02:00
|
|
|
completed_at TIMESTAMP,
|
2022-03-24 21:14:08 +01:00
|
|
|
|
|
|
|
FOREIGN KEY (user_mxid) REFERENCES "user"(mxid) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
|
|
FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE
|
|
|
|
)
|
2022-04-06 16:45:45 +02:00
|
|
|
`, queueIDColumnTypeModifier))
|
2022-03-24 21:14:08 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}}
|
|
|
|
}
|