feat: add account automation and isolated chat
- add account-level auto rating and daily polish tasks\n- add cached historical chat, media, emoji, and per-account realtime sync\n- add SQLite, MySQL, and PostgreSQL migrations and regression coverage\n- align account, sidebar, and chat interfaces with the new workflows
This commit is contained in:
1 parent
d7abbfb2b6
commit
67d7214930
59 files changed
+5202
-211
No files matched your search
@@ -0,0 +1,72 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE account_task_settings (
|
||||
cookie_id TEXT PRIMARY KEY REFERENCES cookies(id) ON DELETE CASCADE,
|
||||
auto_rate_enabled INTEGER NOT NULL DEFAULT 0,
|
||||
rate_content TEXT NOT NULL DEFAULT '不错的买家,交易愉快',
|
||||
auto_polish_enabled INTEGER NOT NULL DEFAULT 0,
|
||||
polish_time VARCHAR(5) NOT NULL DEFAULT '03:00',
|
||||
last_rate_scan_at BIGINT NOT NULL DEFAULT 0,
|
||||
last_polish_date VARCHAR(10) NOT NULL DEFAULT '',
|
||||
last_polish_at BIGINT NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE account_task_runs (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
run_key TEXT NOT NULL UNIQUE,
|
||||
cookie_id TEXT NOT NULL REFERENCES cookies(id) ON DELETE CASCADE,
|
||||
task_type VARCHAR(32) NOT NULL,
|
||||
target_id TEXT NOT NULL DEFAULT '',
|
||||
run_date VARCHAR(10) NOT NULL DEFAULT '',
|
||||
status VARCHAR(24) NOT NULL,
|
||||
success_count INTEGER NOT NULL DEFAULT 0,
|
||||
failed_count INTEGER NOT NULL DEFAULT 0,
|
||||
error_message TEXT NOT NULL DEFAULT '',
|
||||
next_retry_at BIGINT NOT NULL DEFAULT 0,
|
||||
started_at BIGINT NOT NULL,
|
||||
finished_at BIGINT NOT NULL DEFAULT 0
|
||||
);
|
||||
CREATE INDEX idx_account_task_runs_account_type ON account_task_runs(cookie_id, task_type, started_at DESC);
|
||||
CREATE INDEX idx_account_task_runs_retry ON account_task_runs(status, next_retry_at);
|
||||
|
||||
CREATE TABLE chat_sessions (
|
||||
cookie_id TEXT NOT NULL REFERENCES cookies(id) ON DELETE CASCADE,
|
||||
chat_id TEXT NOT NULL,
|
||||
buyer_id TEXT NOT NULL DEFAULT '',
|
||||
buyer_name TEXT NOT NULL DEFAULT '',
|
||||
buyer_avatar_url TEXT NOT NULL DEFAULT '',
|
||||
item_id TEXT NOT NULL DEFAULT '',
|
||||
item_title TEXT NOT NULL DEFAULT '',
|
||||
last_message TEXT NOT NULL DEFAULT '',
|
||||
last_message_at BIGINT NOT NULL DEFAULT 0,
|
||||
unread_count INTEGER NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
PRIMARY KEY (cookie_id, chat_id)
|
||||
);
|
||||
CREATE INDEX idx_chat_sessions_account_recent ON chat_sessions(cookie_id, last_message_at DESC);
|
||||
|
||||
CREATE TABLE chat_messages (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
cookie_id TEXT NOT NULL,
|
||||
chat_id TEXT NOT NULL,
|
||||
message_key TEXT NOT NULL,
|
||||
direction VARCHAR(16) NOT NULL,
|
||||
sender_id TEXT NOT NULL DEFAULT '',
|
||||
sender_name TEXT NOT NULL DEFAULT '',
|
||||
message_type VARCHAR(24) NOT NULL DEFAULT 'text',
|
||||
content TEXT NOT NULL DEFAULT '',
|
||||
status VARCHAR(24) NOT NULL DEFAULT 'received',
|
||||
sent_at BIGINT NOT NULL,
|
||||
created_at BIGINT NOT NULL,
|
||||
UNIQUE (cookie_id, message_key),
|
||||
FOREIGN KEY (cookie_id, chat_id) REFERENCES chat_sessions(cookie_id, chat_id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX idx_chat_messages_conversation ON chat_messages(cookie_id, chat_id, sent_at DESC, id DESC);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE IF EXISTS chat_messages;
|
||||
DROP TABLE IF EXISTS chat_sessions;
|
||||
DROP TABLE IF EXISTS account_task_runs;
|
||||
DROP TABLE IF EXISTS account_task_settings;
|
||||
@@ -0,0 +1,12 @@
|
||||
-- +goose Up
|
||||
UPDATE chat_messages SET direction='outgoing', sender_name='我'
|
||||
WHERE sender_id=cookie_id AND direction='incoming';
|
||||
UPDATE chat_sessions cs SET buyer_id=COALESCE((
|
||||
SELECT m.sender_id FROM chat_messages m
|
||||
WHERE m.cookie_id=cs.cookie_id AND m.chat_id=cs.chat_id
|
||||
AND m.direction='incoming' AND m.sender_id<>cs.cookie_id
|
||||
ORDER BY m.sent_at DESC,m.id DESC LIMIT 1
|
||||
), cs.buyer_id);
|
||||
|
||||
-- +goose Down
|
||||
-- Data repair is intentionally irreversible.
|
||||
Reference in new issue
Block a user