Files
medical-mall/docs/sql/00_overview.md

33 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 00 概览:商城数据库总体设计
## 目标与定位
本数据库设计面向 **PostgreSQL + Supabase** 的电商/订阅混合业务,核心目标:
- **统一用户体系复用**:复用 `public.ak_users`,商城域只做扩展(`ml_` 前缀)。
- **安全优先Supabase 直连友好)**:使用 RLSRow Level Security+ `auth.uid()` 做行级数据隔离。
- **对外访问友好SEO / URL**:核心表同时提供 `UUID id`(内部主键)与 `SERIAL cid`(对外可读 ID配合 `slug` 与 SEO 函数。
- **数据库承载关键一致性**:触发器/函数/约束实现 `updated_at` 自动维护、默认地址唯一、库存汇总、订单状态时间戳与销量累计等。
- **快速迭代与可扩展**:大量使用 `JSONB` 承载可变结构(属性、媒体、地址快照、适用范围、订阅 features/metadata 等)。
## SQL 资料来源
- 迁移/建库主脚本:
- `doc_mall/database/mall_migration.sql`(偏幂等、增量迁移)
- `doc_mall/database/complete_mall_database.sql`(偏一次性完整初始化,包含更多视图/函数/RLS/SEO
- 订阅模块:`doc_mall/create_mall_subscription_tables.sql`
- 检查/测试脚本:`mall_sql/tests/mall_database_check.sql`
## 术语
- **SPU**:商品主表(本库对应 `ml_products`
- **SKU**:商品规格明细(本库对应 `ml_product_skus`
- **RLS**Row Level Security行级安全策略
## 一句话总结
- **Supabase 优先**RLS + `auth.uid()`
- **快速迭代优先**JSONB + 配置化)
- **数据库保证关键一致性**(触发器/函数/约束/视图)
- **对外可读与 SEO 友好**`UUID id` + `SERIAL cid` + `slug`