| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/usr/bin/env node
- const {
- SOURCES,
- DIMENSIONS,
- CORE_FIELDS,
- INDEXES,
- buildDdl,
- buildQueryMap
- } = require('../mcp/src/features/tihao-sourcing/pgy-schema');
- function main() {
- // schema 覆盖选号核心维度
- const dimensions = Object.keys(DIMENSIONS);
- ['fanRange', 'interaction', 'price', 'verticality', 'score', 'location', 'cpm', 'activity', 'fansProfile'].forEach(key => {
- assert(dimensions.includes(key), `应包含选号维度 ${key}`);
- });
- // 报价字段必采(field_dictionary 的 ⭐ 标记)
- ['picture_price', 'video_price', 'lower_price'].forEach(field => {
- assert(CORE_FIELDS[field] && CORE_FIELDS[field].priority === 3, `${field} 应为必采报价字段`);
- });
- // 每个维度字段都应能在 CORE_FIELDS 里找到或属于派生
- for (const dim of Object.values(DIMENSIONS)) {
- assert(Array.isArray(dim.fields) && dim.fields.length > 0, `维度 ${dim.zh} 应有字段`);
- assert(dim.query && typeof dim.query === 'object', `维度 ${dim.zh} 应有查询示例`);
- }
- // 索引唯一键
- assert(INDEXES.some(index => index.name === 'uk_blogger_id' && index.options.unique), '应有 blogger_id 唯一索引');
- assert(INDEXES.length >= 6, '应覆盖选号热路径索引');
- // DDL 与查询映射生成
- const ddl = buildDdl('pgy_blogger');
- assert(ddl.includes('createCollection'), 'DDL 应包含建表语句');
- assert(ddl.includes('uk_blogger_id'), 'DDL 应包含唯一索引');
- const queryMap = buildQueryMap();
- assert(queryMap.includes('选号查询映射'), '查询映射应有标题');
- assert(queryMap.includes('粉丝范围'), '查询映射应包含粉丝维度');
- assert(queryMap.includes('estimate_video_cpm'), '查询映射应包含 CPM 字段');
- console.log(JSON.stringify({
- ok: true,
- dimensionCount: dimensions.length,
- coreFieldCount: Object.keys(CORE_FIELDS).length,
- sourceCount: Object.keys(SOURCES).length,
- indexCount: INDEXES.length
- }, null, 2));
- }
- function assert(condition, message) {
- if (!condition) throw new Error(message);
- }
- if (require.main === module) main();
|