-- Ticket13:自然结束与区间补采的来源游标、采集器原始历史和恢复元数据。 ALTER TABLE t_test ADD COLUMN backfill_status VARCHAR(32) NOT NULL DEFAULT 'NOT_STARTED' COMMENT '区间补采状态:NOT_STARTED、RUNNING、WAITING、FAILED' AFTER runtime_attach, ADD COLUMN backfill_started_at_utc DATETIME(3) NULL AFTER backfill_status, ADD COLUMN backfill_completed_at_utc DATETIME(3) NULL AFTER backfill_started_at_utc, ADD KEY idx_test_backfill_status (reception_status, test_status, backfill_status); CREATE TABLE t_test_backfill_cursor ( cursor_id BIGINT NOT NULL AUTO_INCREMENT, test_id BIGINT NOT NULL, binding_id BIGINT NOT NULL, source_type VARCHAR(32) NOT NULL, source_id BIGINT NOT NULL, source_channel_code VARCHAR(64) NULL, protocol_test_id VARCHAR(64) NULL, next_position BIGINT NOT NULL DEFAULT 1, source_status VARCHAR(32) NOT NULL DEFAULT 'PENDING', protocol_metadata JSON NULL, last_error VARCHAR(1000) NULL, updated_at_utc DATETIME(3) NOT NULL, PRIMARY KEY (cursor_id), UNIQUE KEY uk_test_backfill_source (test_id, binding_id, source_type, source_id, source_channel_code), KEY idx_test_backfill_work (source_status, updated_at_utc), CONSTRAINT fk_backfill_cursor_test FOREIGN KEY (test_id) REFERENCES t_test (test_id), CONSTRAINT fk_backfill_cursor_binding FOREIGN KEY (binding_id) REFERENCES t_test_channel_binding (binding_id), CONSTRAINT chk_backfill_cursor_source CHECK (source_type IN ('CABINET_CHANNEL', 'COLLECTOR_CHANNEL')), CONSTRAINT chk_backfill_cursor_status CHECK (source_status IN ('PENDING', 'RUNNING', 'COMPLETED', 'FAILED')), CONSTRAINT chk_backfill_cursor_position CHECK (next_position > 0) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='测试来源区间补采游标'; CREATE TABLE t_test_collector_sample ( sample_id BIGINT NOT NULL AUTO_INCREMENT, test_id BIGINT NOT NULL, binding_id BIGINT NOT NULL, collector_id BIGINT NOT NULL, collector_channel_code VARCHAR(64) NOT NULL, sequence_id BIGINT NOT NULL, device_time_utc DATETIME(3) NOT NULL, device_time_raw VARCHAR(64) NOT NULL, server_received_at_utc DATETIME(3) NOT NULL, metric_code VARCHAR(191) NOT NULL, metric_value DECIMAL(30,12) NULL, unit VARCHAR(32) NOT NULL, content_sha256 BINARY(32) NOT NULL, PRIMARY KEY (sample_id), UNIQUE KEY uk_collector_history_sample (collector_id, collector_channel_code, sequence_id, metric_code), KEY idx_collector_sample_test_time (test_id, binding_id, device_time_utc), CONSTRAINT fk_collector_sample_test FOREIGN KEY (test_id) REFERENCES t_test (test_id), CONSTRAINT fk_collector_sample_binding FOREIGN KEY (binding_id) REFERENCES t_test_channel_binding (binding_id), CONSTRAINT fk_collector_sample_collector FOREIGN KEY (collector_id) REFERENCES t_collector (collector_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='采集器原始历史测量'; ALTER TABLE t_test_sample ADD COLUMN reception_interval_id BIGINT NULL AFTER binding_id, ADD KEY idx_sample_interval (reception_interval_id), ADD CONSTRAINT fk_sample_reception_interval FOREIGN KEY (reception_interval_id) REFERENCES t_test_reception_interval (interval_id);