23 lines
1.2 KiB
SQL
23 lines
1.2 KiB
SQL
CREATE TABLE outbound_operations_old (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
account_id INTEGER NOT NULL REFERENCES accounts(id),
|
|
swt_sid TEXT NOT NULL,
|
|
event_id TEXT NOT NULL UNIQUE,
|
|
operation TEXT NOT NULL CHECK(operation IN ('end_conversation', 'change_contact_name')),
|
|
payload TEXT NOT NULL,
|
|
occurred_at DATETIME NOT NULL,
|
|
delivery_status TEXT NOT NULL DEFAULT 'pending' CHECK(delivery_status IN ('pending', 'delivering', 'delivered', 'uncertain', 'failed')),
|
|
claimed_at DATETIME,
|
|
attempts INTEGER NOT NULL DEFAULT 0,
|
|
next_attempt_at DATETIME,
|
|
last_error TEXT,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
-- Preserve the source table if accept_transfer rows make rollback unsafe.
|
|
INSERT INTO outbound_operations_old SELECT * FROM outbound_operations;
|
|
DROP TABLE outbound_operations;
|
|
ALTER TABLE outbound_operations_old RENAME TO outbound_operations;
|
|
CREATE INDEX idx_outbound_operations_ready ON outbound_operations(delivery_status, next_attempt_at, account_id, id);
|
|
CREATE UNIQUE INDEX idx_outbound_one_delivering_operation_per_account ON outbound_operations(account_id) WHERE delivery_status = 'delivering';
|