Browse Source

已绑定项目信息绑定应用信息

dev
巴林闲侠 2 years ago
parent
commit
cc644af98b
  1. 14
      api/app/lib/controllers/project/index.js
  2. 15
      api/app/lib/index.js
  3. 43
      api/app/lib/models/app.js
  4. 32
      api/app/lib/models/project_app.js
  5. 2
      api/sequelize-automate.config.js
  6. 12
      script/0.0.3/3.alert_project_app.sql
  7. 12
      script/0.0.3/4.create_app.sql
  8. 5
      script/0.0.3/5.alert_app_alarm.sql
  9. 6
      script/0.0.3/6.alert_app_inspection.sql

14
api/app/lib/controllers/project/index.js

@ -4,10 +4,8 @@ async function appList (ctx) {
try {
const models = ctx.fs.dc.models;
const appRes = await models.ProjectApp.findAll({
attributes: {
exclude: ['projectId']
}
const appRes = await models.App.findAll({
})
ctx.status = 200;
ctx.body = appRes
@ -33,13 +31,7 @@ async function pomsProject (ctx) {
},
distinct: true,
include: {
model: models.ProjectApp,
where: {
lock: false
},
attributes: {
exclude: ['projectId']
}
model: models.App,
}
}

15
api/app/lib/index.js

@ -55,15 +55,20 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
});
const {
AppInspection, ProjectApp, ProjectCorrelation, AppAlarm
AppInspection, ProjectApp, ProjectCorrelation, AppAlarm, App
} = dc.models;
AppInspection.belongsTo(ProjectApp, { foreignKey: 'projectAppId', targetKey: 'id' });
ProjectApp.hasMany(AppInspection, { foreignKey: 'projectAppId', sourceKey: 'id' });
AppInspection.belongsTo(App, { foreignKey: 'projectAppId', targetKey: 'id' });
App.hasMany(AppInspection, { foreignKey: 'projectAppId', sourceKey: 'id' });
ProjectApp.belongsTo(ProjectCorrelation, { foreignKey: 'projectId', targetKey: 'id' });
ProjectCorrelation.hasMany(ProjectApp, { foreignKey: 'projectId', sourceKey: 'id' });
AppAlarm.belongsTo(ProjectApp, { foreignKey: 'projectAppId', targetKey: 'id' });
ProjectApp.hasMany(AppAlarm, { foreignKey: 'projectAppId', sourceKey: 'id' });
ProjectApp.belongsTo(App, { foreignKey: 'appId', targetKey: 'id' });
App.hasMany(ProjectApp, { foreignKey: 'appId', sourceKey: 'id' });
ProjectCorrelation.belongsToMany(App, { through: ProjectApp, foreignKey: 'projectId', otherKey: 'appId' });
AppAlarm.belongsTo(App, { foreignKey: 'projectAppId', targetKey: 'id' });
App.hasMany(AppAlarm, { foreignKey: 'projectAppId', sourceKey: 'id' });
};

43
api/app/lib/models/app.js

@ -0,0 +1,43 @@
/* eslint-disable*/
'use strict';
module.exports = dc => {
const DataTypes = dc.ORM;
const sequelize = dc.orm;
const App = sequelize.define("app", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: true,
field: "id",
autoIncrement: true,
unique: "app_id_uindex"
},
name: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "name",
autoIncrement: false
},
url: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "url",
autoIncrement: false
}
}, {
tableName: "app",
comment: "",
indexes: []
});
dc.models.App = App;
return App;
};

32
api/app/lib/models/project_app.js

@ -15,24 +15,6 @@ module.exports = dc => {
autoIncrement: true,
unique: "project_app_id_uindex"
},
name: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "name",
autoIncrement: false
},
url: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "url",
autoIncrement: false
},
projectId: {
type: DataTypes.INTEGER,
allowNull: false,
@ -46,14 +28,18 @@ module.exports = dc => {
model: "projectCorrelation"
}
},
lock: {
type: DataTypes.BOOLEAN,
allowNull: false,
appId: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "lock",
autoIncrement: false
field: "app_id",
autoIncrement: false,
references: {
key: "id",
model: "app"
}
}
}, {
tableName: "project_app",

2
api/sequelize-automate.config.js

@ -26,7 +26,7 @@ module.exports = {
dir: './app/lib/models', // 指定输出 models 文件的目录
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir`
tables: ['app_alarm'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
tables: ['project_app'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性
tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中
ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面

12
script/0.0.3/3.alert_project_app.sql

@ -1,2 +1,12 @@
alter table project_app drop column name;
alter table project_app
add lock boolean default false not null;
add app_id int;
alter table project_app drop column url;
alter table project_app drop column lock;
alter table project_app
add constraint project_app_app_id_fk
foreign key (app_id) references app;

12
script/0.0.3/4.create_app.sql

@ -0,0 +1,12 @@
create table if not exists app
(
id serial not null,
name varchar(256) not null,
url varchar(1024) not null,
constraint app_pk
primary key (id)
);
create unique index if not exists app_id_uindex
on app (id);

5
script/0.0.3/5.alert_app_alarm.sql

@ -0,0 +1,5 @@
alter table app_alarm drop constraint app_alarm_project_app_id_fk;
alter table app_alarm
add constraint app_alarm_app_id_fk
foreign key (project_app_id) references app;

6
script/0.0.3/6.alert_app_inspection.sql

@ -0,0 +1,6 @@
alter table app_inspection drop constraint app_inspection_project_app_id_fk;
alter table app_inspection
add constraint app_inspection_app_id_fk
foreign key (project_app_id) references app;
Loading…
Cancel
Save