feat: 2026-04-15~05-02 累积变更基线 — AI 重构 + Runtime Context + DWS 修复
涵盖(每条对应已存的审计记录): - AI 模块拆分:apps/backend/app/ai/apps -> prompts/(8 个 APP + app2a 派生) audit: 2026-04-20__ai-module-complete.md - admin-web AI 管理套件:AIDashboard / AIOperations / AIRunLogs / AITriggers / TriggerManager audit: 2026-04-21__admin-web-ai-management-suite.md - App2 财务洞察 prompt v3 -> v5.1 + 小程序 AI 接入(chat / board-finance) audit: 2026-04-22__app2_prompt_v5_1_and_miniprogram_ai_insight.md - App2 prewarm 全过滤器 + AI 触发器 cron reschedule audit: 2026-04-21__app2-finance-prewarm-all-filters.md migration: 20260420_ai_trigger_jobs_and_app2_prewarm.sql / 20260421_app2_prewarm_cron_reschedule.sql - AppType 联合类型对齐 + adminAiAppTypes.test.ts audit: 2026-04-30__admin_web_ai_app_type_alignment.md - DashScope tokens_used 提取修复 audit: 2026-04-30__backend_dashscope_tokens_used_extraction.md - App3 线索完整详情 prompt audit: 2026-05-01__backend_app3_full_detail_prompt.md - Runtime Context 沙箱(5-1~5-2 主线): - 后端 schema/service + admin_runtime_context / xcx_runtime_clock 两个 router - admin-web RuntimeContext.tsx + miniprogram runtime-clock.ts - migration: 20260501__runtime_context_sandbox.sql - tools/db/verify_admin_web_sandbox.py + verify_sandbox_end_to_end.py - database/changes: 7 份 sandbox_* 验证报告 - 飞球 DWS 修复:finance_area_daily 区域汇总 + task_engine 调整 + RLS 视图业务日上界(migration 20260502 + scripts/ops/gen_rls_business_date_migration.py) 合规: - .gitignore 启用 tmp/ 排除 - 不入仓:apps/etl/connectors/feiqiu/.env(API_TOKEN secret,本地修改保留) 待验证清单: - docs/audit/changes/2026-05-04__cumulative_baseline_pending_verification.md 每个主题的功能完整性 / 上线验证几乎都未收口,按优先级 P0~P3 逐一处理
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
-- 20260420_ai_trigger_jobs_and_app2_prewarm.sql
|
||||
-- 注册 AI 事件触发器 + App2 财务洞察 cron 预热任务
|
||||
--
|
||||
-- 背景:Phase 0.1~0.3 AI 模块收尾。dispatcher 已注册 5 个 handler 到
|
||||
-- trigger_scheduler._JOB_REGISTRY(通过 main.py lifespan 调用),
|
||||
-- 但 biz.trigger_jobs 缺对应数据行,fire_event 查不到事件绑定而失效。
|
||||
--
|
||||
-- 本脚本插入:
|
||||
-- 4 条 event 类型记录:ai_consumption_settled / ai_note_created /
|
||||
-- ai_task_assigned / ai_dws_completed
|
||||
-- 1 条 cron 类型记录:ai_dws_prewarm (每日 08:30 给所有 site 触发 App2 × 8 维度)
|
||||
--
|
||||
-- 幂等:job_name UNIQUE 约束 + ON CONFLICT DO NOTHING。
|
||||
--
|
||||
-- 验证 SQL(执行后):
|
||||
-- 1. SELECT count(*) FROM biz.trigger_jobs WHERE job_type LIKE 'ai_%';
|
||||
-- 应为 5
|
||||
-- 2. SELECT job_name, trigger_condition, trigger_config FROM biz.trigger_jobs
|
||||
-- WHERE trigger_condition = 'event' AND trigger_config->>'event_name' LIKE 'ai_%';
|
||||
-- 应为 4 条,event_name 与 job_name 一致
|
||||
-- 3. SELECT job_name, trigger_config->>'cron_expression' FROM biz.trigger_jobs
|
||||
-- WHERE job_type = 'ai_dws_prewarm';
|
||||
-- 应为 "30 8 * * *"
|
||||
--
|
||||
-- 回滚:
|
||||
-- DELETE FROM biz.trigger_jobs WHERE job_name IN (
|
||||
-- 'ai_consumption_settled', 'ai_note_created',
|
||||
-- 'ai_task_assigned', 'ai_dws_completed', 'ai_dws_prewarm'
|
||||
-- );
|
||||
|
||||
BEGIN;
|
||||
|
||||
-- ── 4 条 event 类型触发器 ──────────────────────────────
|
||||
|
||||
INSERT INTO biz.trigger_jobs
|
||||
(job_type, job_name, trigger_condition, trigger_config, status, description)
|
||||
VALUES
|
||||
(
|
||||
'ai_consumption_settled',
|
||||
'ai_consumption_settled',
|
||||
'event',
|
||||
'{"event_name": "ai_consumption_settled"}'::jsonb,
|
||||
'enabled',
|
||||
'AI 消费事件链:App3 → App8 → App7(+ App4 → App5 含助教)'
|
||||
),
|
||||
(
|
||||
'ai_note_created',
|
||||
'ai_note_created',
|
||||
'event',
|
||||
'{"event_name": "ai_note_created"}'::jsonb,
|
||||
'enabled',
|
||||
'AI 备注事件链:App6 → App8'
|
||||
),
|
||||
(
|
||||
'ai_task_assigned',
|
||||
'ai_task_assigned',
|
||||
'event',
|
||||
'{"event_name": "ai_task_assigned"}'::jsonb,
|
||||
'enabled',
|
||||
'AI 任务分配事件链:App4 → App5'
|
||||
),
|
||||
(
|
||||
'ai_dws_completed',
|
||||
'ai_dws_completed',
|
||||
'event',
|
||||
'{"event_name": "ai_dws_completed"}'::jsonb,
|
||||
'enabled',
|
||||
'AI DWS 完成事件:App2 财务洞察 × 8 时间维度预生成'
|
||||
)
|
||||
ON CONFLICT (job_name) DO NOTHING;
|
||||
|
||||
-- ── 1 条 cron 类型触发器 ───────────────────────────────
|
||||
|
||||
-- 每日 08:30 对所有 active 门店逐个触发 ai_dws_completed 事件,
|
||||
-- 作为 etl-completed 端点之外的兜底机制。
|
||||
INSERT INTO biz.trigger_jobs
|
||||
(job_type, job_name, trigger_condition, trigger_config, status, description)
|
||||
VALUES
|
||||
(
|
||||
'ai_dws_prewarm',
|
||||
'ai_dws_prewarm_0830',
|
||||
'cron',
|
||||
'{"cron_expression": "30 8 * * *"}'::jsonb,
|
||||
'enabled',
|
||||
'App2 财务洞察每日预热:08:30 对所有门店触发 ai_dws_completed × 8 维度'
|
||||
)
|
||||
ON CONFLICT (job_name) DO NOTHING;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,42 @@
|
||||
-- 20260421_app2_prewarm_cron_reschedule.sql
|
||||
-- App2 财务洞察 cron 预热时间从 08:30 调整为 10:00 + 扩展为 72 组合覆盖
|
||||
--
|
||||
-- 背景:用户需求 2026-04-21
|
||||
-- 1) 每日 10:00 为所有门店生成 board-finance 所有筛选组合下的 AI 洞察
|
||||
-- 2) 筛选组合 = 8 时间维度 × 9 区域 = 72 组合/门店
|
||||
-- 3) 前端根据当前筛选条件读缓存(target_id=time__area)
|
||||
--
|
||||
-- 变更:
|
||||
-- 1. job_name rename: ai_dws_prewarm_0830 → ai_dws_prewarm_1000
|
||||
-- 2. cron_expression: "30 8 * * *" → "0 10 * * *"
|
||||
-- 3. description 更新为"72 组合"说明
|
||||
--
|
||||
-- 注:dispatcher._handle_dws_completed 已改为遍历 72 组合,无需额外的 handler 注册。
|
||||
--
|
||||
-- 验证 SQL(执行后):
|
||||
-- 1. SELECT job_name FROM biz.trigger_jobs
|
||||
-- WHERE job_type = 'ai_dws_prewarm';
|
||||
-- 应为 'ai_dws_prewarm_1000'
|
||||
-- 2. SELECT trigger_config->>'cron_expression' FROM biz.trigger_jobs
|
||||
-- WHERE job_type = 'ai_dws_prewarm';
|
||||
-- 应为 '0 10 * * *'
|
||||
-- 3. SELECT count(*) FROM biz.trigger_jobs WHERE job_type LIKE 'ai_%';
|
||||
-- 应为 5(不变)
|
||||
--
|
||||
-- 回滚:
|
||||
-- UPDATE biz.trigger_jobs
|
||||
-- SET job_name = 'ai_dws_prewarm_0830',
|
||||
-- trigger_config = '{"cron_expression": "30 8 * * *"}'::jsonb,
|
||||
-- description = 'App2 财务洞察每日预热:08:30 对所有门店触发 ai_dws_completed × 8 维度'
|
||||
-- WHERE job_type = 'ai_dws_prewarm';
|
||||
|
||||
BEGIN;
|
||||
|
||||
UPDATE biz.trigger_jobs
|
||||
SET
|
||||
job_name = 'ai_dws_prewarm_1000',
|
||||
trigger_config = '{"cron_expression": "0 10 * * *"}'::jsonb,
|
||||
description = 'App2 财务洞察每日预热:10:00 对所有门店触发 ai_dws_completed × 72 组合(8 时间 × 9 区域)'
|
||||
WHERE job_type = 'ai_dws_prewarm';
|
||||
|
||||
COMMIT;
|
||||
117
db/zqyy_app/migrations/20260501__runtime_context_sandbox.sql
Normal file
117
db/zqyy_app/migrations/20260501__runtime_context_sandbox.sql
Normal file
@@ -0,0 +1,117 @@
|
||||
-- 2026-05-01
|
||||
-- 业务运行上下文与沙箱隔离。
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS biz.site_runtime_context (
|
||||
site_id bigint PRIMARY KEY,
|
||||
mode character varying(20) NOT NULL DEFAULT 'live',
|
||||
sandbox_date date,
|
||||
sandbox_instance_id character varying(64),
|
||||
ai_mode character varying(20) NOT NULL DEFAULT 'live',
|
||||
status character varying(20) NOT NULL DEFAULT 'active',
|
||||
reason text,
|
||||
updated_by bigint,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
updated_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
CONSTRAINT site_runtime_context_site_id_fkey
|
||||
FOREIGN KEY (site_id) REFERENCES biz.sites(site_id),
|
||||
CONSTRAINT site_runtime_context_mode_check
|
||||
CHECK (mode IN ('live', 'sandbox')),
|
||||
CONSTRAINT site_runtime_context_ai_mode_check
|
||||
CHECK (ai_mode IN ('live')),
|
||||
CONSTRAINT site_runtime_context_sandbox_check
|
||||
CHECK (
|
||||
(mode = 'live' AND sandbox_date IS NULL AND sandbox_instance_id IS NULL)
|
||||
OR
|
||||
(mode = 'sandbox' AND sandbox_date IS NOT NULL AND sandbox_instance_id IS NOT NULL)
|
||||
)
|
||||
);
|
||||
|
||||
COMMENT ON TABLE biz.site_runtime_context IS '门店业务运行上下文:live 使用真实日期,sandbox 使用指定业务日期并按实例隔离写入。';
|
||||
COMMENT ON COLUMN biz.site_runtime_context.mode IS '运行模式:live / sandbox。';
|
||||
COMMENT ON COLUMN biz.site_runtime_context.sandbox_date IS 'sandbox 模式下系统假设的业务日期。';
|
||||
COMMENT ON COLUMN biz.site_runtime_context.sandbox_instance_id IS 'sandbox 模式写入隔离实例 ID。';
|
||||
COMMENT ON COLUMN biz.site_runtime_context.ai_mode IS 'AI 调用模式;当前固定 live,沙箱也真实调用 DashScope。';
|
||||
|
||||
ALTER TABLE biz.coach_tasks
|
||||
ADD COLUMN IF NOT EXISTS runtime_mode character varying(20) NOT NULL DEFAULT 'live',
|
||||
ADD COLUMN IF NOT EXISTS sandbox_instance_id character varying(64) NOT NULL DEFAULT 'live';
|
||||
|
||||
ALTER TABLE biz.coach_task_transfer_log
|
||||
ADD COLUMN IF NOT EXISTS runtime_mode character varying(20) NOT NULL DEFAULT 'live',
|
||||
ADD COLUMN IF NOT EXISTS sandbox_instance_id character varying(64) NOT NULL DEFAULT 'live';
|
||||
|
||||
ALTER TABLE biz.recall_events
|
||||
ADD COLUMN IF NOT EXISTS runtime_mode character varying(20) NOT NULL DEFAULT 'live',
|
||||
ADD COLUMN IF NOT EXISTS sandbox_instance_id character varying(64) NOT NULL DEFAULT 'live';
|
||||
|
||||
ALTER TABLE biz.coach_task_history
|
||||
ADD COLUMN IF NOT EXISTS runtime_mode character varying(20) NOT NULL DEFAULT 'live',
|
||||
ADD COLUMN IF NOT EXISTS sandbox_instance_id character varying(64) NOT NULL DEFAULT 'live';
|
||||
|
||||
ALTER TABLE biz.ai_cache
|
||||
ADD COLUMN IF NOT EXISTS runtime_mode character varying(20) NOT NULL DEFAULT 'live',
|
||||
ADD COLUMN IF NOT EXISTS sandbox_instance_id character varying(64) NOT NULL DEFAULT 'live';
|
||||
|
||||
ALTER TABLE biz.ai_run_logs
|
||||
ADD COLUMN IF NOT EXISTS runtime_mode character varying(20) NOT NULL DEFAULT 'live',
|
||||
ADD COLUMN IF NOT EXISTS sandbox_instance_id character varying(64) NOT NULL DEFAULT 'live';
|
||||
|
||||
ALTER TABLE biz.ai_trigger_jobs
|
||||
ADD COLUMN IF NOT EXISTS runtime_mode character varying(20) NOT NULL DEFAULT 'live',
|
||||
ADD COLUMN IF NOT EXISTS sandbox_instance_id character varying(64) NOT NULL DEFAULT 'live';
|
||||
|
||||
UPDATE biz.coach_tasks SET runtime_mode = 'live', sandbox_instance_id = 'live' WHERE sandbox_instance_id IS NULL;
|
||||
UPDATE biz.coach_task_transfer_log SET runtime_mode = 'live', sandbox_instance_id = 'live' WHERE sandbox_instance_id IS NULL;
|
||||
UPDATE biz.recall_events SET runtime_mode = 'live', sandbox_instance_id = 'live' WHERE sandbox_instance_id IS NULL;
|
||||
UPDATE biz.coach_task_history SET runtime_mode = 'live', sandbox_instance_id = 'live' WHERE sandbox_instance_id IS NULL;
|
||||
UPDATE biz.ai_cache SET runtime_mode = 'live', sandbox_instance_id = 'live' WHERE sandbox_instance_id IS NULL;
|
||||
UPDATE biz.ai_run_logs SET runtime_mode = 'live', sandbox_instance_id = 'live' WHERE sandbox_instance_id IS NULL;
|
||||
UPDATE biz.ai_trigger_jobs SET runtime_mode = 'live', sandbox_instance_id = 'live' WHERE sandbox_instance_id IS NULL;
|
||||
|
||||
DROP INDEX IF EXISTS biz.idx_coach_tasks_site_assistant_member_type;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_coach_tasks_runtime_unique_active
|
||||
ON biz.coach_tasks (site_id, assistant_id, member_id, task_type, runtime_mode, sandbox_instance_id)
|
||||
WHERE status = 'active';
|
||||
|
||||
DROP INDEX IF EXISTS biz.idx_recall_events_site_assistant_member_day;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_recall_events_runtime_site_assistant_member_day
|
||||
ON biz.recall_events (
|
||||
site_id,
|
||||
assistant_id,
|
||||
member_id,
|
||||
runtime_mode,
|
||||
sandbox_instance_id,
|
||||
(date_trunc('day', pay_time AT TIME ZONE 'Asia/Shanghai'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_coach_tasks_runtime_assistant_status
|
||||
ON biz.coach_tasks (site_id, runtime_mode, sandbox_instance_id, assistant_id, status);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_cache_runtime_lookup
|
||||
ON biz.ai_cache (cache_type, site_id, runtime_mode, sandbox_instance_id, target_id, created_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_trigger_jobs_runtime_site
|
||||
ON biz.ai_trigger_jobs (site_id, runtime_mode, sandbox_instance_id, event_type, status);
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- 回滚参考:
|
||||
-- BEGIN;
|
||||
-- DROP INDEX IF EXISTS biz.idx_ai_trigger_jobs_runtime_site;
|
||||
-- DROP INDEX IF EXISTS biz.idx_ai_cache_runtime_lookup;
|
||||
-- DROP INDEX IF EXISTS biz.idx_coach_tasks_runtime_assistant_status;
|
||||
-- DROP INDEX IF EXISTS biz.idx_recall_events_runtime_site_assistant_member_day;
|
||||
-- CREATE UNIQUE INDEX idx_recall_events_site_assistant_member_day ON biz.recall_events USING btree (site_id, assistant_id, member_id, (date_trunc('day', pay_time AT TIME ZONE 'Asia/Shanghai')));
|
||||
-- DROP INDEX IF EXISTS biz.idx_coach_tasks_runtime_unique_active;
|
||||
-- CREATE UNIQUE INDEX idx_coach_tasks_site_assistant_member_type ON biz.coach_tasks USING btree (site_id, assistant_id, member_id, task_type) WHERE status = 'active';
|
||||
-- ALTER TABLE biz.ai_trigger_jobs DROP COLUMN IF EXISTS sandbox_instance_id, DROP COLUMN IF EXISTS runtime_mode;
|
||||
-- ALTER TABLE biz.ai_run_logs DROP COLUMN IF EXISTS sandbox_instance_id, DROP COLUMN IF EXISTS runtime_mode;
|
||||
-- ALTER TABLE biz.ai_cache DROP COLUMN IF EXISTS sandbox_instance_id, DROP COLUMN IF EXISTS runtime_mode;
|
||||
-- ALTER TABLE biz.coach_task_history DROP COLUMN IF EXISTS sandbox_instance_id, DROP COLUMN IF EXISTS runtime_mode;
|
||||
-- ALTER TABLE biz.recall_events DROP COLUMN IF EXISTS sandbox_instance_id, DROP COLUMN IF EXISTS runtime_mode;
|
||||
-- ALTER TABLE biz.coach_task_transfer_log DROP COLUMN IF EXISTS sandbox_instance_id, DROP COLUMN IF EXISTS runtime_mode;
|
||||
-- ALTER TABLE biz.coach_tasks DROP COLUMN IF EXISTS sandbox_instance_id, DROP COLUMN IF EXISTS runtime_mode;
|
||||
-- DROP TABLE IF EXISTS biz.site_runtime_context;
|
||||
-- COMMIT;
|
||||
@@ -1,6 +1,6 @@
|
||||
-- =============================================================================
|
||||
-- zqyy_app / biz(核心业务表(任务/备注/触发器))
|
||||
-- 生成日期:2026-04-06
|
||||
-- 生成日期:2026-05-02
|
||||
-- 来源:测试库(通过脚本自动导出)
|
||||
-- =============================================================================
|
||||
|
||||
@@ -16,11 +16,11 @@ CREATE SEQUENCE IF NOT EXISTS biz.cfg_task_generator_params_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.coach_task_history_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.coach_task_transfer_log_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.coach_tasks_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.recall_events_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.connectors_id_seq AS integer;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.dws_assistant_task_monthly_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.excel_upload_log_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.notes_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.recall_events_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.salary_adjustments_id_seq AS bigint;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.site_code_history_id_seq AS integer;
|
||||
CREATE SEQUENCE IF NOT EXISTS biz.sites_id_seq AS integer;
|
||||
@@ -41,7 +41,9 @@ CREATE TABLE biz.ai_cache (
|
||||
triggered_by character varying(100),
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
expires_at timestamp with time zone,
|
||||
status character varying(20) DEFAULT 'valid'::character varying
|
||||
status character varying(20) DEFAULT 'valid'::character varying,
|
||||
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
|
||||
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE biz.ai_conversations (
|
||||
@@ -86,7 +88,9 @@ CREATE TABLE biz.ai_run_logs (
|
||||
session_id character varying(100),
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
finished_at timestamp with time zone,
|
||||
alert_status character varying(20) DEFAULT NULL::character varying
|
||||
alert_status character varying(20) DEFAULT NULL::character varying,
|
||||
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
|
||||
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE biz.ai_trigger_jobs (
|
||||
@@ -102,7 +106,9 @@ CREATE TABLE biz.ai_trigger_jobs (
|
||||
started_at timestamp with time zone,
|
||||
finished_at timestamp with time zone,
|
||||
error_message text,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
|
||||
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE biz.cfg_task_generator_params (
|
||||
@@ -124,7 +130,9 @@ CREATE TABLE biz.coach_task_history (
|
||||
old_task_type character varying(50),
|
||||
new_task_type character varying(50),
|
||||
detail jsonb,
|
||||
created_at timestamp with time zone DEFAULT now()
|
||||
created_at timestamp with time zone DEFAULT now(),
|
||||
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
|
||||
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE biz.coach_task_transfer_log (
|
||||
@@ -138,7 +146,9 @@ CREATE TABLE biz.coach_task_transfer_log (
|
||||
transfer_reason text,
|
||||
guard_checks jsonb,
|
||||
transfer_score numeric,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
|
||||
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE biz.coach_tasks (
|
||||
@@ -154,24 +164,15 @@ CREATE TABLE biz.coach_tasks (
|
||||
abandon_reason text,
|
||||
completed_at timestamp with time zone,
|
||||
completed_task_type character varying(50),
|
||||
completion_type character varying(10),
|
||||
parent_task_id bigint,
|
||||
created_at timestamp with time zone DEFAULT now(),
|
||||
updated_at timestamp with time zone DEFAULT now(),
|
||||
transfer_count integer DEFAULT 0 NOT NULL,
|
||||
transferred_from bigint,
|
||||
transferred_at timestamp with time zone
|
||||
);
|
||||
|
||||
CREATE TABLE biz.recall_events (
|
||||
id bigint DEFAULT nextval('biz.recall_events_id_seq'::regclass) NOT NULL,
|
||||
site_id bigint NOT NULL,
|
||||
assistant_id bigint NOT NULL,
|
||||
member_id bigint NOT NULL,
|
||||
pay_time timestamp with time zone NOT NULL,
|
||||
task_id bigint,
|
||||
task_type character varying(50),
|
||||
created_at timestamp with time zone DEFAULT now()
|
||||
transferred_at timestamp with time zone,
|
||||
completion_type character varying(10),
|
||||
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
|
||||
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE biz.connectors (
|
||||
@@ -232,6 +233,19 @@ CREATE TABLE biz.notes (
|
||||
score smallint
|
||||
);
|
||||
|
||||
CREATE TABLE biz.recall_events (
|
||||
id bigint DEFAULT nextval('biz.recall_events_id_seq'::regclass) NOT NULL,
|
||||
site_id bigint NOT NULL,
|
||||
assistant_id bigint NOT NULL,
|
||||
member_id bigint NOT NULL,
|
||||
pay_time timestamp with time zone NOT NULL,
|
||||
task_id bigint,
|
||||
task_type character varying(50),
|
||||
created_at timestamp with time zone DEFAULT now(),
|
||||
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
|
||||
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE biz.salary_adjustments (
|
||||
id bigint DEFAULT nextval('biz.salary_adjustments_id_seq'::regclass) NOT NULL,
|
||||
site_id bigint NOT NULL,
|
||||
@@ -256,6 +270,19 @@ CREATE TABLE biz.site_code_history (
|
||||
retired_at timestamp with time zone
|
||||
);
|
||||
|
||||
CREATE TABLE biz.site_runtime_context (
|
||||
site_id bigint NOT NULL,
|
||||
mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
|
||||
sandbox_date date,
|
||||
sandbox_instance_id character varying(64),
|
||||
ai_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
|
||||
status character varying(20) DEFAULT 'active'::character varying NOT NULL,
|
||||
reason text,
|
||||
updated_by bigint,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
updated_at timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE biz.sites (
|
||||
id integer DEFAULT nextval('biz.sites_id_seq'::regclass) NOT NULL,
|
||||
tenant_id integer NOT NULL,
|
||||
@@ -354,12 +381,14 @@ ALTER TABLE biz.dws_assistant_task_monthly ADD CONSTRAINT dws_assistant_task_mon
|
||||
ALTER TABLE biz.excel_upload_log ADD CONSTRAINT excel_upload_log_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE biz.notes ADD CONSTRAINT notes_task_id_fkey FOREIGN KEY (task_id) REFERENCES biz.coach_tasks(id);
|
||||
ALTER TABLE biz.notes ADD CONSTRAINT notes_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE biz.recall_events ADD CONSTRAINT recall_events_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE biz.recall_events ADD CONSTRAINT recall_events_task_id_fkey FOREIGN KEY (task_id) REFERENCES biz.coach_tasks(id);
|
||||
ALTER TABLE biz.recall_events ADD CONSTRAINT recall_events_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE biz.salary_adjustments ADD CONSTRAINT salary_adjustments_upload_batch_id_fkey FOREIGN KEY (upload_batch_id) REFERENCES biz.excel_upload_log(id);
|
||||
ALTER TABLE biz.salary_adjustments ADD CONSTRAINT salary_adjustments_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE biz.site_code_history ADD CONSTRAINT site_code_history_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE biz.site_code_history ADD CONSTRAINT site_code_history_site_code_key UNIQUE (site_code);
|
||||
ALTER TABLE biz.site_runtime_context ADD CONSTRAINT site_runtime_context_site_id_fkey FOREIGN KEY (site_id) REFERENCES biz.sites(site_id);
|
||||
ALTER TABLE biz.site_runtime_context ADD CONSTRAINT site_runtime_context_pkey PRIMARY KEY (site_id);
|
||||
ALTER TABLE biz.sites ADD CONSTRAINT sites_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES biz.tenants(id);
|
||||
ALTER TABLE biz.sites ADD CONSTRAINT sites_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE biz.sites ADD CONSTRAINT sites_site_code_key UNIQUE (site_code);
|
||||
@@ -379,6 +408,7 @@ ALTER TABLE biz.trigger_jobs ADD CONSTRAINT trigger_jobs_job_name_key UNIQUE (jo
|
||||
-- 索引
|
||||
CREATE INDEX idx_ai_cache_cleanup ON biz.ai_cache USING btree (cache_type, site_id, target_id, created_at);
|
||||
CREATE INDEX idx_ai_cache_lookup ON biz.ai_cache USING btree (cache_type, site_id, target_id, created_at DESC);
|
||||
CREATE INDEX idx_ai_cache_runtime_lookup ON biz.ai_cache USING btree (cache_type, site_id, runtime_mode, sandbox_instance_id, target_id, created_at DESC);
|
||||
CREATE INDEX idx_ai_conv_app_site ON biz.ai_conversations USING btree (app_id, site_id, created_at DESC);
|
||||
CREATE INDEX idx_ai_conv_context ON biz.ai_conversations USING btree (user_id, site_id, context_type, context_id, last_message_at DESC NULLS LAST) WHERE (context_type IS NOT NULL);
|
||||
CREATE INDEX idx_ai_conv_last_msg ON biz.ai_conversations USING btree (user_id, site_id, last_message_at DESC NULLS LAST);
|
||||
@@ -390,18 +420,20 @@ CREATE INDEX idx_ai_run_logs_created_brin ON biz.ai_run_logs USING brin (created
|
||||
CREATE INDEX idx_ai_run_logs_site_app ON biz.ai_run_logs USING btree (site_id, app_type);
|
||||
CREATE INDEX idx_ai_run_logs_status ON biz.ai_run_logs USING btree (status);
|
||||
CREATE INDEX idx_ai_trigger_jobs_dedup ON biz.ai_trigger_jobs USING btree (event_type, member_id, site_id, created_at) WHERE ((status)::text <> 'skipped_duplicate'::text);
|
||||
CREATE INDEX idx_ai_trigger_jobs_runtime_site ON biz.ai_trigger_jobs USING btree (site_id, runtime_mode, sandbox_instance_id, event_type, status);
|
||||
CREATE INDEX idx_ai_trigger_jobs_site ON biz.ai_trigger_jobs USING btree (site_id, event_type);
|
||||
CREATE INDEX idx_ai_trigger_jobs_status ON biz.ai_trigger_jobs USING btree (status);
|
||||
CREATE INDEX idx_transfer_log_member ON biz.coach_task_transfer_log USING btree (member_id, created_at DESC);
|
||||
CREATE INDEX idx_transfer_log_site_created ON biz.coach_task_transfer_log USING btree (site_id, created_at DESC);
|
||||
CREATE INDEX idx_coach_tasks_assistant_status ON biz.coach_tasks USING btree (site_id, assistant_id, status);
|
||||
CREATE UNIQUE INDEX idx_coach_tasks_site_assistant_member_type ON biz.coach_tasks USING btree (site_id, assistant_id, member_id, task_type) WHERE ((status)::text = 'active'::text);
|
||||
CREATE INDEX idx_coach_tasks_runtime_assistant_status ON biz.coach_tasks USING btree (site_id, runtime_mode, sandbox_instance_id, assistant_id, status);
|
||||
CREATE UNIQUE INDEX idx_coach_tasks_runtime_unique_active ON biz.coach_tasks USING btree (site_id, assistant_id, member_id, task_type, runtime_mode, sandbox_instance_id) WHERE ((status)::text = 'active'::text);
|
||||
CREATE INDEX idx_task_monthly_assistant ON biz.dws_assistant_task_monthly USING btree (assistant_id, stat_month DESC);
|
||||
CREATE INDEX idx_task_monthly_site_month ON biz.dws_assistant_task_monthly USING btree (site_id, stat_month DESC);
|
||||
CREATE INDEX idx_excel_log_site ON biz.excel_upload_log USING btree (site_id, created_at DESC);
|
||||
CREATE INDEX idx_notes_target ON biz.notes USING btree (site_id, target_type, target_id);
|
||||
CREATE INDEX idx_salary_adj_assistant_month ON biz.salary_adjustments USING btree (assistant_id, salary_month);
|
||||
CREATE UNIQUE INDEX idx_recall_events_site_assistant_member_day ON biz.recall_events USING btree (site_id, assistant_id, member_id, (date_trunc('day', pay_time AT TIME ZONE 'Asia/Shanghai')));
|
||||
CREATE INDEX idx_recall_events_assistant_pay ON biz.recall_events USING btree (site_id, assistant_id, pay_time);
|
||||
CREATE UNIQUE INDEX idx_recall_events_runtime_site_assistant_member_day ON biz.recall_events USING btree (site_id, assistant_id, member_id, runtime_mode, sandbox_instance_id, date_trunc('day'::text, (pay_time AT TIME ZONE 'Asia/Shanghai'::text)));
|
||||
CREATE INDEX idx_salary_adj_assistant_month ON biz.salary_adjustments USING btree (assistant_id, salary_month);
|
||||
CREATE INDEX idx_salary_adj_site_month ON biz.salary_adjustments USING btree (site_id, salary_month);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user