在准备环境前提交次全部更改。
This commit is contained in:
@@ -82,18 +82,23 @@ COMMENT ON VIEW app.v_assistant IS '助教视图:封装 core.dim_assistant。'
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 4. v_assistant_daily — 助教日明细视图
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- CHANGE 2026-02-15 | 修复视图列名,对齐 dws.dws_assistant_daily_detail 实际表结构
|
||||
CREATE OR REPLACE VIEW app.v_assistant_daily AS
|
||||
SELECT
|
||||
d.id,
|
||||
d.site_id,
|
||||
d.tenant_id,
|
||||
d.assistant_id,
|
||||
d.assistant_nickname,
|
||||
d.stat_date,
|
||||
d.total_service_hours,
|
||||
d.total_service_count,
|
||||
d.total_revenue,
|
||||
d.basic_hours,
|
||||
d.extra_hours,
|
||||
d.tip_hours,
|
||||
d.total_hours,
|
||||
d.base_hours,
|
||||
d.bonus_hours,
|
||||
d.room_hours,
|
||||
d.total_ledger_amount,
|
||||
d.unique_customers,
|
||||
d.unique_tables,
|
||||
d.created_at
|
||||
FROM dws.dws_assistant_daily_detail d;
|
||||
|
||||
@@ -102,18 +107,27 @@ COMMENT ON VIEW app.v_assistant_daily IS '助教日明细视图:封装 dws.dws
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 5. v_finance_daily — 财务日报视图
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- CHANGE 2026-02-15 | 修复视图列名,对齐 dws.dws_finance_daily_summary 实际表结构
|
||||
CREATE OR REPLACE VIEW app.v_finance_daily AS
|
||||
SELECT
|
||||
f.id,
|
||||
f.site_id,
|
||||
f.tenant_id,
|
||||
f.stat_date,
|
||||
f.total_revenue,
|
||||
f.table_fee_revenue,
|
||||
f.goods_revenue,
|
||||
f.assistant_revenue,
|
||||
f.recharge_revenue,
|
||||
f.total_orders,
|
||||
f.total_customers,
|
||||
f.gross_amount,
|
||||
f.table_fee_amount,
|
||||
f.goods_amount,
|
||||
f.assistant_pd_amount,
|
||||
f.assistant_cx_amount,
|
||||
f.discount_total,
|
||||
f.confirmed_income,
|
||||
f.cash_inflow_total,
|
||||
f.recharge_count,
|
||||
f.recharge_total,
|
||||
f.order_count,
|
||||
f.member_order_count,
|
||||
f.guest_order_count,
|
||||
f.avg_order_amount,
|
||||
f.created_at
|
||||
FROM dws.dws_finance_daily_summary f;
|
||||
|
||||
@@ -122,16 +136,23 @@ COMMENT ON VIEW app.v_finance_daily IS '财务日报视图:封装 dws.dws_fina
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 6. v_member_consumption — 会员消费汇总视图
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- CHANGE 2026-02-15 | 修复视图列名,对齐 dws.dws_member_consumption_summary 实际表结构
|
||||
CREATE OR REPLACE VIEW app.v_member_consumption AS
|
||||
SELECT
|
||||
mc.id,
|
||||
mc.site_id,
|
||||
mc.tenant_id,
|
||||
mc.member_id,
|
||||
mc.total_visits,
|
||||
mc.total_consumption,
|
||||
mc.last_visit_date,
|
||||
mc.first_visit_date,
|
||||
mc.avg_consumption,
|
||||
mc.stat_date,
|
||||
mc.member_nickname,
|
||||
mc.card_grade_name,
|
||||
mc.total_visit_count,
|
||||
mc.total_consume_amount,
|
||||
mc.total_recharge_amount,
|
||||
mc.last_consume_date,
|
||||
mc.first_consume_date,
|
||||
mc.days_since_last,
|
||||
mc.customer_tier,
|
||||
mc.created_at
|
||||
FROM dws.dws_member_consumption_summary mc;
|
||||
|
||||
@@ -140,16 +161,21 @@ COMMENT ON VIEW app.v_member_consumption IS '会员消费汇总视图:封装 d
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 7. v_order_summary — 订单汇总视图
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- CHANGE 2026-02-15 | 修复视图列名,对齐 dws.dws_order_summary 实际表结构
|
||||
CREATE OR REPLACE VIEW app.v_order_summary AS
|
||||
SELECT
|
||||
os.site_id,
|
||||
os.order_settle_id,
|
||||
os.order_trade_no,
|
||||
os.order_date,
|
||||
os.tenant_id,
|
||||
os.member_id,
|
||||
os.total_amount,
|
||||
os.actual_amount,
|
||||
os.settle_time,
|
||||
os.pay_status,
|
||||
os.member_flag,
|
||||
os.order_original_amount,
|
||||
os.order_final_amount,
|
||||
os.total_paid_amount,
|
||||
os.refund_amount,
|
||||
os.net_income,
|
||||
os.created_at
|
||||
FROM dws.dws_order_summary os;
|
||||
|
||||
|
||||
@@ -2048,8 +2048,89 @@ COMMENT ON COLUMN ods.store_goods_sales_records.source_endpoint IS '【说明】
|
||||
COMMENT ON COLUMN ods.store_goods_sales_records.fetched_at IS '【说明】ETL 元数据:采集/入库时间戳,用于口径对齐与增量处理。 【示例】2025-11-10T00:00:00+08:00(ETL 元数据:采集/入库时间戳,用于口径对齐与增量处理)。 【JSON字段】store_goods_sales_records.json - ETL元数据 - 无。';
|
||||
|
||||
|
||||
-- ============================================================
|
||||
-- "取最新版本"复合索引
|
||||
-- 支持 DISTINCT ON (pk) ORDER BY pk, fetched_at DESC 查询模式
|
||||
-- 迁移脚本:migrations/2026-02-17__add_ods_latest_version_indexes.sql
|
||||
-- ============================================================
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_member_profiles_latest
|
||||
ON ods.member_profiles (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_member_balance_changes_latest
|
||||
ON ods.member_balance_changes (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_member_stored_value_cards_latest
|
||||
ON ods.member_stored_value_cards (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_recharge_settlements_latest
|
||||
ON ods.recharge_settlements (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_settlement_records_latest
|
||||
ON ods.settlement_records (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_assistant_cancellation_records_latest
|
||||
ON ods.assistant_cancellation_records (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_assistant_accounts_master_latest
|
||||
ON ods.assistant_accounts_master (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_assistant_service_records_latest
|
||||
ON ods.assistant_service_records (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_site_tables_master_latest
|
||||
ON ods.site_tables_master (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_table_fee_discount_records_latest
|
||||
ON ods.table_fee_discount_records (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_table_fee_transactions_latest
|
||||
ON ods.table_fee_transactions (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_goods_stock_movements_latest
|
||||
ON ods.goods_stock_movements (siteGoodsStockId, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_stock_goods_category_tree_latest
|
||||
ON ods.stock_goods_category_tree (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_goods_stock_summary_latest
|
||||
ON ods.goods_stock_summary (siteGoodsId, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_payment_transactions_latest
|
||||
ON ods.payment_transactions (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_refund_transactions_latest
|
||||
ON ods.refund_transactions (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_platform_coupon_redemption_records_latest
|
||||
ON ods.platform_coupon_redemption_records (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_tenant_goods_master_latest
|
||||
ON ods.tenant_goods_master (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_group_buy_packages_latest
|
||||
ON ods.group_buy_packages (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_group_buy_redemption_records_latest
|
||||
ON ods.group_buy_redemption_records (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_settlement_ticket_details_latest
|
||||
ON ods.settlement_ticket_details (orderSettleId, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_store_goods_master_latest
|
||||
ON ods.store_goods_master (id, fetched_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ods_store_goods_sales_records_latest
|
||||
ON ods.store_goods_sales_records (id, fetched_at DESC);
|
||||
|
||||
|
||||
-- AI_CHANGELOG:
|
||||
-- - 日期: 2026-02-17
|
||||
-- - Prompt: ods-dedup-standardize Task 5.1
|
||||
-- - 直接原因: ODS 去重标准化需要 DISTINCT ON (pk) ORDER BY pk, fetched_at DESC 查询模式的索引支持
|
||||
-- - 变更摘要: 为全部 23 张 ODS 表添加 (业务主键, fetched_at DESC) 复合索引定义
|
||||
-- - 风险与验证: DDL 文档性文件,新环境初始化时自动创建索引;已有环境通过迁移脚本部署
|
||||
--
|
||||
-- - 日期: 2026-02-14
|
||||
-- - Prompt: P20260214-070000 — ODS 清理与文档标注(5 项任务)
|
||||
-- - 直接原因: option_name(store_goods_sales_records)和 able_site_transfer(member_stored_value_cards)在 API 中不存在且全 NULL,需从 DDL 中注释化
|
||||
|
||||
Reference in New Issue
Block a user