diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 5cb7374..1411eb9 100644 --- a/api/app/lib/index.js +++ b/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' }); }; diff --git a/api/app/lib/models/check_items.js b/api/app/lib/models/check_items.js new file mode 100644 index 0000000..eee21a5 --- /dev/null +++ b/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; +}; \ No newline at end of file diff --git a/api/app/lib/models/check_items_group.js b/api/app/lib/models/check_items_group.js new file mode 100644 index 0000000..3cb1399 --- /dev/null +++ b/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; +}; \ No newline at end of file diff --git a/script/1.0.0/schema/5.create_check_items.sql b/script/1.0.0/schema/5.create_check_items.sql new file mode 100644 index 0000000..3a0ae9a --- /dev/null +++ b/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) +); \ No newline at end of file