pgy-schema-smoke.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env node
  2. const {
  3. SOURCES,
  4. DIMENSIONS,
  5. CORE_FIELDS,
  6. INDEXES,
  7. buildDdl,
  8. buildQueryMap
  9. } = require('../mcp/src/features/tihao-sourcing/pgy-schema');
  10. function main() {
  11. // schema 覆盖选号核心维度
  12. const dimensions = Object.keys(DIMENSIONS);
  13. ['fanRange', 'interaction', 'price', 'verticality', 'score', 'location', 'cpm', 'activity', 'fansProfile'].forEach(key => {
  14. assert(dimensions.includes(key), `应包含选号维度 ${key}`);
  15. });
  16. // 报价字段必采(field_dictionary 的 ⭐ 标记)
  17. ['picture_price', 'video_price', 'lower_price'].forEach(field => {
  18. assert(CORE_FIELDS[field] && CORE_FIELDS[field].priority === 3, `${field} 应为必采报价字段`);
  19. });
  20. // 每个维度字段都应能在 CORE_FIELDS 里找到或属于派生
  21. for (const dim of Object.values(DIMENSIONS)) {
  22. assert(Array.isArray(dim.fields) && dim.fields.length > 0, `维度 ${dim.zh} 应有字段`);
  23. assert(dim.query && typeof dim.query === 'object', `维度 ${dim.zh} 应有查询示例`);
  24. }
  25. // 索引唯一键
  26. assert(INDEXES.some(index => index.name === 'uk_blogger_id' && index.options.unique), '应有 blogger_id 唯一索引');
  27. assert(INDEXES.length >= 6, '应覆盖选号热路径索引');
  28. // DDL 与查询映射生成
  29. const ddl = buildDdl('pgy_blogger');
  30. assert(ddl.includes('createCollection'), 'DDL 应包含建表语句');
  31. assert(ddl.includes('uk_blogger_id'), 'DDL 应包含唯一索引');
  32. const queryMap = buildQueryMap();
  33. assert(queryMap.includes('选号查询映射'), '查询映射应有标题');
  34. assert(queryMap.includes('粉丝范围'), '查询映射应包含粉丝维度');
  35. assert(queryMap.includes('estimate_video_cpm'), '查询映射应包含 CPM 字段');
  36. console.log(JSON.stringify({
  37. ok: true,
  38. dimensionCount: dimensions.length,
  39. coreFieldCount: Object.keys(CORE_FIELDS).length,
  40. sourceCount: Object.keys(SOURCES).length,
  41. indexCount: INDEXES.length
  42. }, null, 2));
  43. }
  44. function assert(condition, message) {
  45. if (!condition) throw new Error(message);
  46. }
  47. if (require.main === module) main();