50 lines
2.5 KiB
Python
50 lines
2.5 KiB
Python
from sqlalchemy import *
|
|
from sqlalchemy.dialects.mysql import TINYINT
|
|
from sqlalchemy.orm import declarative_base,sessionmaker
|
|
from datetime import datetime
|
|
from core.database import Base, engine
|
|
|
|
# 为了符合三范式,就业表只保存 student_id,不保存学生姓名和班级名称。查询返回时通过关联 students 和 classes 带出学生姓名、班级名称。
|
|
|
|
class Employment(Base):
|
|
__tablename__ = "employments" # 实际数据库的表名字
|
|
id = Column(BigInteger, primary_key=True # 主键
|
|
, autoincrement=True # 声明是自增主键
|
|
,comment="就业信息主键id")
|
|
student_id = Column(Integer, ForeignKey("students.id") # 外键 -> students.id
|
|
, nullable=False # 不允许为null
|
|
, unique=True # 每个学生只对应一条就业信息
|
|
,comment="关联学生id")
|
|
employment_status = Column(String(30)
|
|
, default="not_started"
|
|
, nullable=False
|
|
,comment="就业状态:not_started/job_hunting/offered/employed")
|
|
employment_open_date = Column(Date
|
|
,comment="就业开放时间")
|
|
offer_date = Column(Date
|
|
,comment="offer下发时间")
|
|
company_name = Column(String(100)
|
|
, comment="就业公司名称")
|
|
salary = Column(DECIMAL(10, 2) # 定点小数薪资,最多10位数字,小数占2位
|
|
, comment="就业薪资")
|
|
remark = Column(String(255)
|
|
,default=None
|
|
, comment="备注信息")
|
|
created_at = Column(DateTime
|
|
, default=datetime.now
|
|
, server_default=text("CURRENT_TIMESTAMP")
|
|
, nullable=False
|
|
, comment="创建时间")
|
|
updated_at = Column(DateTime
|
|
, default=datetime.now
|
|
, onupdate=datetime.now
|
|
, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
|
|
, nullable=False
|
|
,comment="更新时间")
|
|
is_deleted = Column(TINYINT
|
|
,default=0
|
|
,server_default=text("0")
|
|
,nullable=False
|
|
,comment="逻辑删除:0正常,1删除")
|
|
|