123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- // Sequelize模型定义示例
- const { Sequelize, DataTypes } = require('sequelize');
- // 数据库连接配置
- const sequelize = new Sequelize('job_management', 'username', 'password', {
- host: 'localhost',
- dialect: 'mysql',
- });
- // 部门模型
- const Department = sequelize.define('Department', {
- name: {
- type: DataTypes.STRING(100),
- allowNull: false,
- },
- description: {
- type: DataTypes.TEXT,
- },
- });
- // 岗位模型
- const Job = sequelize.define('Job', {
- title: {
- type: DataTypes.STRING(100),
- allowNull: false,
- },
- location: {
- type: DataTypes.STRING(100),
- allowNull: false,
- },
- status: {
- type: DataTypes.ENUM('active', 'paused', 'draft'),
- defaultValue: 'draft',
- },
- pendingResumes: {
- type: DataTypes.INTEGER,
- defaultValue: 0,
- field: 'pending_resumes',
- },
- passedResumes: {
- type: DataTypes.INTEGER,
- defaultValue: 0,
- field: 'passed_resumes',
- },
- jobDescription: {
- type: DataTypes.TEXT,
- field: 'job_description',
- },
- requirements: {
- type: DataTypes.TEXT,
- },
- salaryRange: {
- type: DataTypes.STRING(50),
- field: 'salary_range',
- },
- });
- // 简历模型
- const Resume = sequelize.define('Resume', {
- candidateName: {
- type: DataTypes.STRING(100),
- allowNull: false,
- field: 'candidate_name',
- },
- email: {
- type: DataTypes.STRING(100),
- allowNull: false,
- },
- phone: {
- type: DataTypes.STRING(20),
- },
- status: {
- type: DataTypes.ENUM('pending', 'passed', 'rejected', 'interview'),
- defaultValue: 'pending',
- },
- resumeText: {
- type: DataTypes.TEXT,
- field: 'resume_text',
- },
- score: {
- type: DataTypes.DECIMAL(5, 2),
- defaultValue: 0.0,
- },
- });
- // 用户模型
- const User = sequelize.define('User', {
- username: {
- type: DataTypes.STRING(50),
- allowNull: false,
- unique: true,
- },
- passwordHash: {
- type: DataTypes.STRING(255),
- allowNull: false,
- field: 'password_hash',
- },
- role: {
- type: DataTypes.ENUM('admin', 'recruiter', 'viewer'),
- defaultValue: 'recruiter',
- },
- });
- // 关联关系
- Department.hasMany(Job, { foreignKey: 'department_id' });
- Job.belongsTo(Department, { foreignKey: 'department_id' });
- Job.hasMany(Resume, { foreignKey: 'job_id' });
- Resume.belongsTo(Job, { foreignKey: 'job_id' });
- module.exports = {
- sequelize,
- Department,
- Job,
- Resume,
- User,
- };
|