'use strict'; module.exports = app => { const { STRING, BIGINT, DATE } = app.Sequelize; const WorkbenchMember = app.model.define('workbench_member', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键ID', }, workbench_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '工作台ID,关联 wms_workbench.id', }, user_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '账号ID,关联 wms_account.id;非系统账号用户为 NULL', }, user_name: { type: STRING(128), allowNull: true, comment: '成员名称快照(非系统账号用户显示名)', }, created_at: { type: DATE, allowNull: false, comment: '创建时间', }, updated_at: { type: DATE, allowNull: false, comment: '更新时间', }, deleted_at: { type: DATE, allowNull: true, comment: '软删除时间', }, }, { tableName: 'wms_workbench_member', timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', paranoid: true, deletedAt: 'deleted_at', comment: '工作台成员/用户登录副表', indexes: [ { name: 'idx_workbench_id', fields: [ 'workbench_id' ] }, { name: 'idx_user_id', fields: [ 'user_id' ] }, ], }); WorkbenchMember.associate = () => { app.model.WorkbenchMember.belongsTo(app.model.Workbench, { foreignKey: 'workbench_id', targetKey: 'id', as: 'workbench', }); app.model.WorkbenchMember.belongsTo(app.model.Account, { foreignKey: 'user_id', targetKey: 'id', as: 'user', }); }; return WorkbenchMember; };