63fbbe1225
Major Changes: - Pipeline Queue integration completed (internal.file + pipeline.commands) - Fixed old job_worker database compatibility with new command_queue table - Compiled Swift OCR binary (was missing, causing empty OCR results) - Added deep scan functionality through re-scan API Fixes: - Changed CommandJob.id from i32 to i64 for database compatibility - Added UUID generation in create_command (message_id field) - Fixed claim_pending_commands to query queue_name = 'internal.file' - Fixed field mappings: command_id → message_id, job_type → command_type - Added support for 'processing' status in CommandJobStatus Queue System: - internal.file queue: for register/unregister/re-scan commands (job_worker) - pipeline.commands queue: for vectorize/store_asrx/etc commands (pipeline_worker) Documentation: - Added comprehensive queue system documentation - Created M4 workspace status reports - Updated AGENTS.md with queue system details
158 lines
5.1 KiB
PL/PgSQL
158 lines
5.1 KiB
PL/PgSQL
-- ============================================
|
|
-- Replay System Schema
|
|
-- ============================================
|
|
-- Date: 2026-10-11
|
|
-- Purpose: Implement command replay functionality for stability testing
|
|
-- Features: Idempotency verification, batch replay, scenario testing
|
|
-- ============================================
|
|
|
|
-- 1. Replay Sessions 表
|
|
CREATE TABLE replay_sessions (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
-- Session 信息
|
|
session_id VARCHAR(36) NOT NULL UNIQUE DEFAULT replace(gen_random_uuid()::text, '-', ''),
|
|
session_name VARCHAR(255),
|
|
replay_type VARCHAR(20) NOT NULL CHECK (
|
|
replay_type IN ('success', 'failed', 'batch', 'scenario')
|
|
),
|
|
|
|
-- 源命令过滤条件
|
|
source_filter JSONB NOT NULL DEFAULT '{}',
|
|
|
|
-- 配置
|
|
config JSONB NOT NULL DEFAULT '{}',
|
|
|
|
-- 执行状态
|
|
status VARCHAR(20) NOT NULL DEFAULT 'pending' CHECK (
|
|
status IN ('pending', 'running', 'paused', 'completed', 'failed', 'cancelled')
|
|
),
|
|
|
|
-- 统计信息
|
|
total_commands INTEGER DEFAULT 0,
|
|
processed_commands INTEGER DEFAULT 0,
|
|
succeeded_commands INTEGER DEFAULT 0,
|
|
failed_commands INTEGER DEFAULT 0,
|
|
skipped_commands INTEGER DEFAULT 0,
|
|
|
|
-- 结果对比
|
|
comparison_results JSONB DEFAULT '[]',
|
|
|
|
-- 性能指标
|
|
started_at TIMESTAMP WITH TIME ZONE,
|
|
completed_at TIMESTAMP WITH TIME ZONE,
|
|
duration_secs DOUBLE PRECISION,
|
|
|
|
-- 错误信息
|
|
error_message TEXT,
|
|
|
|
-- 时间戳
|
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
|
|
-- 用户信息
|
|
user_id BIGINT
|
|
);
|
|
|
|
-- 索引
|
|
CREATE INDEX idx_replay_sessions_status ON replay_sessions (status, created_at);
|
|
CREATE INDEX idx_replay_sessions_type ON replay_sessions (replay_type, created_at);
|
|
CREATE INDEX idx_replay_sessions_user ON replay_sessions (user_id, created_at);
|
|
|
|
COMMENT ON TABLE replay_sessions IS 'Replay session for stability testing';
|
|
COMMENT ON COLUMN replay_sessions.replay_type IS 'success=verify idempotency, failed=test recovery, batch=stress test, scenario=test specific flow';
|
|
COMMENT ON COLUMN replay_sessions.source_filter IS 'Filter criteria for source commands';
|
|
COMMENT ON COLUMN replay_sessions.config IS 'Replay configuration (concurrency, delay, etc.)';
|
|
|
|
-- 2. Replay Commands 表
|
|
CREATE TABLE replay_commands (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
-- 关联信息
|
|
session_id VARCHAR(36) NOT NULL,
|
|
original_command_id VARCHAR(36) NOT NULL,
|
|
replay_command_id VARCHAR(36),
|
|
|
|
-- 执行状态
|
|
status VARCHAR(20) NOT NULL DEFAULT 'pending' CHECK (
|
|
status IN ('pending', 'running', 'completed', 'failed', 'skipped')
|
|
),
|
|
|
|
-- 原始命令信息
|
|
original_job_type VARCHAR(20),
|
|
original_file_path VARCHAR(512),
|
|
original_file_uuid VARCHAR(32),
|
|
original_payload JSONB,
|
|
|
|
-- 结果对比
|
|
original_result JSONB,
|
|
replay_result JSONB,
|
|
comparison_status VARCHAR(20) CHECK (
|
|
comparison_status IN ('match', 'mismatch', 'error', 'skipped')
|
|
),
|
|
differences JSONB,
|
|
|
|
-- 性能指标
|
|
original_duration_secs DOUBLE PRECISION,
|
|
replay_duration_secs DOUBLE PRECISION,
|
|
|
|
-- 错误信息
|
|
error_message TEXT,
|
|
retry_count INTEGER DEFAULT 0,
|
|
|
|
-- 时间戳
|
|
started_at TIMESTAMP WITH TIME ZONE,
|
|
completed_at TIMESTAMP WITH TIME ZONE,
|
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
|
|
-- 外键
|
|
FOREIGN KEY (session_id) REFERENCES replay_sessions(session_id) ON DELETE CASCADE
|
|
);
|
|
|
|
-- 索引
|
|
CREATE INDEX idx_replay_commands_session ON replay_commands (session_id);
|
|
CREATE INDEX idx_replay_commands_status ON replay_commands (status);
|
|
CREATE INDEX idx_replay_commands_original ON replay_commands (original_command_id);
|
|
|
|
COMMENT ON TABLE replay_commands IS 'Individual command replay tracking';
|
|
COMMENT ON COLUMN replay_commands.comparison_status IS 'match=identical result, mismatch=difference detected, error=failed';
|
|
|
|
-- 3. 触发器:自动更新 updated_at
|
|
CREATE OR REPLACE FUNCTION update_replay_sessions_updated_at()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
NEW.updated_at = NOW();
|
|
RETURN NEW;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
CREATE TRIGGER trigger_update_replay_sessions_updated_at
|
|
BEFORE UPDATE ON replay_sessions
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION update_replay_sessions_updated_at();
|
|
|
|
-- 4. 视图:Replay 统计
|
|
CREATE VIEW replay_stats AS
|
|
SELECT
|
|
replay_type,
|
|
status,
|
|
COUNT(*) as session_count,
|
|
AVG(duration_secs) as avg_duration_secs,
|
|
AVG(succeeded_commands::FLOAT / NULLIF(total_commands, 0)) as avg_success_rate
|
|
FROM replay_sessions
|
|
WHERE status = 'completed'
|
|
GROUP BY replay_type, status;
|
|
|
|
COMMENT ON VIEW replay_stats IS 'Replay session statistics';
|
|
|
|
-- ============================================
|
|
-- 示例数据(测试用)
|
|
-- ============================================
|
|
|
|
-- 插入测试 session
|
|
-- INSERT INTO replay_sessions (session_name, replay_type, source_filter, config)
|
|
-- VALUES ('Test idempotency', 'success', '{"limit": 10}', '{"concurrency": 5}');
|
|
|
|
-- ============================================
|
|
-- Migration 完成
|
|
-- ============================================ |