Browse Source

(+) 检查项及分组表结构

master
liujiangyong 2 years ago
parent
commit
2650c84c9e
  1. 6
      api/app/lib/index.js
  2. 37
      api/app/lib/models/check_items.js
  3. 30
      api/app/lib/models/check_items_group.js
  4. 15
      script/1.0.0/schema/5.create_check_items.sql

6
api/app/lib/index.js

@ -53,7 +53,8 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
require(`./models/${filename}`)(dc)
});
const { Department, User, UserResource, Resource, Project, Point, PatrolPlan
const { Department, User, UserResource, Resource, Project, Point, PatrolPlan,
CheckItems, CheckItemsGroup
} = dc.models;
UserResource.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' });
@ -74,4 +75,7 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
PatrolPlan.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' });
User.hasMany(PatrolPlan, { foreignKey: 'userId', sourceKey: 'id' });
CheckItems.belongsTo(CheckItemsGroup, { foreignKey: 'groupId', targetKey: 'id' });
CheckItemsGroup.hasMany(CheckItems, { foreignKey: 'groupId', sourceKey: 'id' });
};

37
api/app/lib/models/check_items.js

@ -0,0 +1,37 @@
/* eslint-disable*/
'use strict';
module.exports = dc => {
const DataTypes = dc.ORM;
const sequelize = dc.orm;
const CheckItems = sequelize.define("check_items", {
id: {
field: "id",
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: {
field: "name",
type: DataTypes.STRING,
allowNull: false,
primaryKey: false,
autoIncrement: false
},
groupId: {
field: "group_id",
type: DataTypes.INTEGER,
allowNull: true,
primaryKey: false,
autoIncrement: false
}
}, {
tableName: "check_items",
comment: "",
indexes: []
});
dc.models.CheckItems = CheckItems;
return CheckItems;
};

30
api/app/lib/models/check_items_group.js

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

15
script/1.0.0/schema/5.create_check_items.sql

@ -0,0 +1,15 @@
DROP TABLE IF EXISTS "public"."check_items_group";
CREATE TABLE "public"."check_items_group" (
"id" serial,
"name" varchar(255) NOT NULL,
PRIMARY KEY ("id")
);
DROP TABLE IF EXISTS "public"."check_items";
CREATE TABLE "public"."check_items" (
"id" serial,
"name" varchar(255) NOT NULL,
"group_id" int,
PRIMARY KEY ("id"),
FOREIGN KEY (group_id) REFERENCES check_items_group(id)
);
Loading…
Cancel
Save