WMS_MAIN/database/migrations/20260923150000-create-method-doc-tables.js

172 lines
5.0 KiB
JavaScript
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.

'use strict';
/**
* API 方法文档库表化(2026-09-23):
* - wms_api_method_doc:方法文档表(methods/system.json 的维护源)
* - wms_method_doc_meta:文档元信息表(docName 维度单行:描述/全局 headers/version/updatedAt)
*
* methods/system.json 由导出脚本 script/method-doc-export.cjs 生成,docs 页面仍读文件。
*/
const DOC_TABLE = 'wms_api_method_doc';
const META_TABLE = 'wms_method_doc_meta';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable(DOC_TABLE, {
id: {
type: Sequelize.BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键',
},
method: {
type: Sequelize.STRING(128),
allowNull: false,
comment: '方法名(如 wechat.userList)',
},
module: {
type: Sequelize.STRING(64),
allowNull: false,
comment: '模块标识(group.module,如 wechat)',
},
group_name: {
type: Sequelize.STRING(128),
allowNull: false,
defaultValue: '',
comment: '分组名称(groupName)',
},
description: {
type: Sequelize.TEXT,
allowNull: true,
comment: '接口说明',
},
is_need_login: {
type: Sequelize.TINYINT(1),
allowNull: false,
defaultValue: 1,
comment: '是否需登录',
},
is_need_auth: {
type: Sequelize.TINYINT(1),
allowNull: false,
defaultValue: 0,
comment: '是否需权限鉴权',
},
headers: {
type: Sequelize.TEXT('long'),
allowNull: true,
comment: '请求头(JSON 数组文本,LONGTEXT 保留原键序)',
},
params: {
type: Sequelize.TEXT('long'),
allowNull: true,
comment: '入参(JSON 数组文本,LONGTEXT 保留原键序)',
},
response: {
type: Sequelize.TEXT('long'),
allowNull: true,
comment: '响应字段(JSON 数组文本,LONGTEXT 保留原键序)',
},
errors: {
type: Sequelize.TEXT('long'),
allowNull: true,
comment: '错误码(JSON 数组文本,LONGTEXT 保留原键序)',
},
group_sort: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '分组排序(导入时的原始顺序)',
},
item_sort: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '组内排序(导入时的原始顺序)',
},
status: {
type: Sequelize.TINYINT(1),
allowNull: false,
defaultValue: 1,
comment: '状态:1 启用 0 下线(导出时排除)',
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '更新时间',
},
}, {
comment: 'API 方法文档表(methods/system.json 的库表化维护源)',
});
await queryInterface.addIndex(DOC_TABLE, [ 'method' ], {
unique: true,
name: 'uk_method',
});
await queryInterface.addIndex(DOC_TABLE, [ 'module' ], {
name: 'idx_module',
});
await queryInterface.addIndex(DOC_TABLE, [ 'status', 'module', 'group_sort', 'item_sort' ], {
name: 'idx_export_order',
});
await queryInterface.createTable(META_TABLE, {
id: {
type: Sequelize.TINYINT,
primaryKey: true,
allowNull: false,
comment: '固定 1(单行)',
},
doc_name: {
type: Sequelize.STRING(64),
allowNull: false,
unique: true,
comment: '文档名(system/qimen...)',
},
module: {
type: Sequelize.STRING(64),
allowNull: false,
defaultValue: 'system',
comment: '文档顶层 module',
},
description: {
type: Sequelize.TEXT,
allowNull: true,
comment: '文档顶层描述',
},
headers: {
type: Sequelize.TEXT('long'),
allowNull: true,
comment: '文档全局请求头(JSON 数组文本,LONGTEXT 保留原键序)',
},
version: {
type: Sequelize.STRING(32),
allowNull: false,
defaultValue: '0.3.0',
comment: '文档版本(顶层 version)',
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '更新时间(顶层 updatedAt)',
},
}, {
comment: 'API 文档元信息表(docName 维度单行)',
});
},
async down(queryInterface) {
await queryInterface.dropTable(META_TABLE);
await queryInterface.dropTable(DOC_TABLE);
},
};