api-server/prisma/seed-membership.sql
wangdl 648bee0ad0
All checks were successful
Deploy API Server / build-and-unit (push) Successful in 40s
Deploy API Server / current-integration (push) Successful in 33s
Deploy API Server / backward-compat (push) Successful in 0s
Deploy API Server / deploy (push) Successful in 1m7s
docs: M-MEMBER-01-CLOSE-06A 生产 Schema Drift 修复 Runbook + Seed
- appAccountToken 全量回填 SQL(UUID 幂等,已验证 0 NULL / 0 dup / 0 invalid)
- MembershipPlan 数据更新(Free/Premium quotas)
- StoreProduct seed(Apple monthly/yearly)
- PlanQuota 18 条全面 seed(9 种类型 x 2 计划)
- 生产修复 Runbook(8 步 Migration + 回滚预案)
- 本地验证: 68 tables, schema 与 Prisma 一致
2026-06-27 13:37:40 +08:00

78 lines
4.2 KiB
SQL
Raw Permalink 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.

-- ═══════════════════════════════════════════════════════
-- 知习 会员基础数据 Seed (幂等)
--
-- 执行方式: mysql -u root -p < seed.sql
-- 幂等: 使用 INSERT IGNORE + ON DUPLICATE KEY UPDATE
--
-- 生产执行前必须: mysqldump zhixi_prod > backup_$(date +%Y%m%d).sql
-- ═══════════════════════════════════════════════════════
-- ── 1. MembershipPlan ──
-- NOTE: maxStorageBytes is BIGINT; PlanQuota.limit is INT (max 2147483647)
-- Storage bytes quota uses INT_MAX for "unlimited" in current schema
INSERT INTO MembershipPlan (id, code, name, priceMonthly, priceYearly,
maxKnowledgeBases, maxStorageBytes, maxFileSizeBytes,
monthlyOcrPages, monthlyVisionPages, monthlyChatCount, monthlyAiAnalysisCount,
monthlyRecallCount, monthlyCardGenCount, monthlyQuizCount,
isActive, updatedAt)
VALUES
('free_prod_plan', 'free', 'Free',
0, 0,
1, 104857600, 10485760, -- 1 KB, 100MB, 10MB
0, 0, 10, 3,
5, 3, 0,
1, NOW()),
('premium_prod_plan', 'premium', 'Premium',
0, 0,
10, 10737418240, 209715200, -- 10 KB, 10GB, 200MB
0, 0, 100, 10,
30, 10, 5,
1, NOW())
ON DUPLICATE KEY UPDATE
name = VALUES(name),
monthlyChatCount = VALUES(monthlyChatCount),
monthlyAiAnalysisCount = VALUES(monthlyAiAnalysisCount),
monthlyRecallCount = VALUES(monthlyRecallCount),
monthlyCardGenCount = VALUES(monthlyCardGenCount),
monthlyQuizCount = VALUES(monthlyQuizCount),
maxKnowledgeBases = VALUES(maxKnowledgeBases),
maxStorageBytes = VALUES(maxStorageBytes),
maxFileSizeBytes = VALUES(maxFileSizeBytes),
updatedAt = NOW();
-- ── 2. PlanQuota (idempotent) ──
-- NOTE: PlanQuota.limit 是 INT最大 2147483647 (约 2GB)。
-- 超出此值的存储配额由 BIGINT maxStorageBytes 控制,不在此表体现。
INSERT IGNORE INTO PlanQuota (id, planId, quotaType, `limit`, unit, windowType, isUnlimited, updatedAt)
VALUES
-- Free plan quotas
(UUID(), 'free_prod_plan', 'active_recall', 5, 'count', 'daily', false, NOW()),
(UUID(), 'free_prod_plan', 'feynman_evaluation', 2, 'count', 'daily', false, NOW()),
(UUID(), 'free_prod_plan', 'quiz_generation', 1, 'count', 'daily', false, NOW()),
(UUID(), 'free_prod_plan', 'learning_analysis', 1, 'count', 'daily', false, NOW()),
(UUID(), 'free_prod_plan', 'flashcard_generation', 1, 'count', 'daily', false, NOW()),
(UUID(), 'free_prod_plan', 'ai_chat_messages', 10, 'count', 'monthly', false, NOW()),
(UUID(), 'free_prod_plan', 'knowledge_base_count', 1, 'count', 'lifetime', false, NOW()),
(UUID(), 'free_prod_plan', 'storage_bytes', 1073741824, 'bytes', 'lifetime', false, NOW()), -- 1GB (INT safe)
(UUID(), 'free_prod_plan', 'file_size_bytes', 10485760, 'bytes', 'per_request', false, NOW()),
-- Premium plan quotas
(UUID(), 'premium_prod_plan', 'active_recall', 30, 'count', 'daily', false, NOW()),
(UUID(), 'premium_prod_plan', 'feynman_evaluation', 10, 'count', 'daily', false, NOW()),
(UUID(), 'premium_prod_plan', 'quiz_generation', 5, 'count', 'daily', false, NOW()),
(UUID(), 'premium_prod_plan', 'learning_analysis', 5, 'count', 'daily', false, NOW()),
(UUID(), 'premium_prod_plan', 'flashcard_generation', 5, 'count', 'daily', false, NOW()),
(UUID(), 'premium_prod_plan', 'ai_chat_messages', 100, 'count', 'monthly', false, NOW()),
(UUID(), 'premium_prod_plan', 'knowledge_base_count', 10, 'count', 'lifetime', false, NOW()),
(UUID(), 'premium_prod_plan', 'storage_bytes', 2147483647, 'bytes', 'lifetime', false, NOW()), -- INT_MAX ≈ 2GB
(UUID(), 'premium_prod_plan', 'file_size_bytes', 209715200, 'bytes', 'per_request', false, NOW());
-- ── 3. StoreProduct ──
INSERT IGNORE INTO StoreProduct (id, platform, productId, planId, billingPeriod, isActive, updatedAt)
VALUES
(UUID(), 'apple', 'zhixi.premium.monthly', 'premium_prod_plan', 'monthly', true, NOW()),
(UUID(), 'apple', 'zhixi.premium.yearly', 'premium_prod_plan', 'yearly', true, NOW());