背景
重点变更
数据库表变更
新增 groups 表,为 interfaces 表新增 groupUniqId 字段。
'use strict';module.exports = {up: async (db, Sequelize) => {const { STRING, UUID, UUIDV4, DATE } = Sequelize;await db.createTable('groups', {uniqId: {type: UUID,defaultValue: UUIDV4,primaryKey: true,allowNull: false,},groupName: {type: STRING,allowNull: false,},groupType: {type: STRING,allowNull: false,},belongedUniqId: {type: STRING,allowNull: false,},createdAt: {type: DATE,allowNull: false,},updatedAt: {type: DATE,allowNull: false,},}, {indexes: [{fields: ['uniqId',],unique: true,},],});await db.addColumn('interfaces', 'groupUniqId', {type: Sequelize.STRING,allowNull: true,});},down: async db => {await db.dropTable('groups');await db.removeColumn('interfaces', 'groupUniqId');},};
Api 变更
新增 分组 相关接口及对应的 controller -> service -> model。
router.get('/api/group', controller.api.group.showAll);router.post('/api/group', controller.api.group.create);router.put('/api/group/:uniqId', controller.api.group.update);router.delete('/api/group/:uniqId', controller.api.group.delete);
为了前端接口场景分组功能的实现,现变更 interface 接口返回的数据结构。 ```javascript router.get(‘/api/interface’, controller.api.interface.showAll);
原数据结构: [ { “protocol”: “http”, “pathname”: “test1”, “method”: “ALL”, “projectUniqId”: “626eec31-8113-4510-ba50-2af8ba4c4ace”, “description”: “interface test”, “currentScene”: “scene1”, “proxyConfig”: {}, “uniqId”: “7db907e1-e63c-40a5-b2f8-0f5fc1c0322c”, “createdAt”: “2022-01-22T09:45:20.682Z”, “updatedAt”: “2022-01-22T09:57:24.774Z” } ]
现数据结构: { “interfaceGroupList”: [ { “groupName”: “默认分组”, “groupUniqId”: “025fa207-0174-42b7-a0b5-26d8c65f73ad”, “interfaceList”: [ { “protocol”: “http”, “pathname”: “test1”, “method”: “ALL”, “projectUniqId”: “626eec31-8113-4510-ba50-2af8ba4c4ace”, “description”: “interface test”, “currentScene”: “scene1”, “proxyConfig”: {}, “uniqId”: “7db907e1-e63c-40a5-b2f8-0f5fc1c0322c”, “groupUniqId”: “025fa207-0174-42b7-a0b5-26d8c65f73ad”, “createdAt”: “2022-01-22T09:45:20.682Z”, “updatedAt”: “2022-01-22T09:57:24.774Z” } ] }, { “groupName”: “group1”, “groupUniqId”: “7a19359a-b2f4-488a-a24e-96a3a53b4f2c”, “interfaceList”: [] } ], “interfaceList”: [ { “protocol”: “http”, “pathname”: “test1”, “method”: “ALL”, “projectUniqId”: “626eec31-8113-4510-ba50-2af8ba4c4ace”, “description”: “interface test”, “currentScene”: “scene1”, “proxyConfig”: {}, “uniqId”: “7db907e1-e63c-40a5-b2f8-0f5fc1c0322c”, “groupUniqId”: “025fa207-0174-42b7-a0b5-26d8c65f73ad”, “createdAt”: “2022-01-22T09:45:20.682Z”, “updatedAt”: “2022-01-22T09:57:24.774Z” } ] }
<a name="Ntiei"></a>### 导入导出数据结构变更由于新增了分组功能,datahub 内部数据的组织结构发生了变化,故导入导出的 json 数据结构也发生了相应的变化,但考虑存在存量 json 数据,导入数据的接口 [依旧兼容](https://github.com/macacajs/macaca-datahub/pull/193/files#diff-40685415d847ce26a00a7da3ba3dc01fa472310e1aae133de9a545d99727f72bR78) 旧的 json 数据,同时也兼容 swagger 数据的导入,但导出的 json 数据均为新结构的数据。```javascript原导出的 project json 数据:[{"pathname": "test1","method": "ALL","description": "interface test","uniqId": "7db907e1-e63c-40a5-b2f8-0f5fc1c0322c","currentScene": "scene1","proxyConfig": {},"scenes": [{"sceneName": "scene1","data": {"success": true,"data": "default data"},"interfaceUniqId": "7db907e1-e63c-40a5-b2f8-0f5fc1c0322c","contextConfig": {"responseDelay": "1","responseStatus": 200,"responseHeaders": {"set-cookie": "name=sample;domain=.smaple.com"}},"uniqId": "56e0fbec-6419-4b36-a44c-588940649553","format": "json","createdAt": "2022-01-22T09:57:17.109Z","updatedAt": "2022-01-22T09:57:24.785Z"}],"schemas": []}]现导出的 project json 数据:[{"groupName": "默认分组","groupUniqId": "b031ecdd-0855-4247-a7d9-24d452cb9e94","interfaceList": [{"pathname": "test1","method": "ALL","description": "interface test","uniqId": "d915c23f-5be0-4dd9-a88c-d1b576878e0e","groupUniqId": "b031ecdd-0855-4247-a7d9-24d452cb9e94","currentScene": "scene1","proxyConfig": {},"scenes": [{"sceneName": "scene1","data": {"success": true,"data": "default data"},"interfaceUniqId": "d915c23f-5be0-4dd9-a88c-d1b576878e0e","contextConfig": {"responseDelay": "1","responseStatus": 200,"responseHeaders": {"set-cookie": "name=sample;domain=.smaple.com"}},"uniqId": "6c532901-f11a-41b6-9434-a4a0bc8d4728","format": "json","createdAt": "2022-02-28T09:13:54.240Z","updatedAt": "2022-02-28T09:13:54.240Z"}],"schemas": []}]}]
单元测试变更
由于新增了场景接口分组功能,导致内部大量单测需要做相应的变化,具体变更见 https://github.com/macacajs/macaca-datahub/pull/193
