From 2650c84c9e45315df67247cba65e27bf5a548bc4 Mon Sep 17 00:00:00 2001 From: liujiangyong Date: Tue, 21 Feb 2023 13:54:06 +0800 Subject: [PATCH] =?UTF-8?q?(+)=20=E6=A3=80=E6=9F=A5=E9=A1=B9=E5=8F=8A?= =?UTF-8?q?=E5=88=86=E7=BB=84=E8=A1=A8=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/index.js | 6 +++- api/app/lib/models/check_items.js | 37 ++++++++++++++++++++ api/app/lib/models/check_items_group.js | 30 ++++++++++++++++ script/1.0.0/schema/5.create_check_items.sql | 15 ++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 api/app/lib/models/check_items.js create mode 100644 api/app/lib/models/check_items_group.js create mode 100644 script/1.0.0/schema/5.create_check_items.sql 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