Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
R
recruit-sys
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李文光
recruit-sys
Commits
4dc0dc3a
Commit
4dc0dc3a
authored
Sep 23, 2026
by
李文光
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: 精简生产部署与数据库基线
parent
d5234f7f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
12 additions
and
366 deletions
+12
-366
AGENTS.md
AGENTS.md
+2
-2
README.md
README.md
+3
-3
0002_resume_evaluations.py
backend/alembic/versions/0002_resume_evaluations.py
+0
-25
db.py
backend/app/db.py
+0
-170
models.py
backend/app/models.py
+1
-56
state_repository.py
backend/app/repositories/state_repository.py
+0
-27
qwenpaw
backend/modules/qwenpaw
+0
-1
start_server.py
backend/scripts/start_server.py
+1
-4
test_state.py
backend/tests/test_state.py
+0
-73
project_handoff.md
docs/project_handoff.md
+5
-5
No files found.
AGENTS.md
View file @
4dc0dc3a
...
@@ -80,7 +80,7 @@
...
@@ -80,7 +80,7 @@
## 5. 测试要求
## 5. 测试要求
-
测试需要鉴权的时候,使用 test1 用户登录, 密码:test123
-
测试需要鉴权的时候,使用 test1 用户登录, 密码:test123
-
**改完后端代码必须跑 `backend\.venv\Scripts\python.exe -m pytest -c backend/pyproject.toml`,
期望 25
passed**
。
-
**改完后端代码必须跑 `backend\.venv\Scripts\python.exe -m pytest -c backend/pyproject.toml`,
当前基线为 138
passed**
。
-
测试必须自包含:
`conftest.py`
已隔离(
`RECRUITMENT_SKIP_ENV_FILES=1`
+ 临时 SQLite/目录),
**禁止依赖真实 `.env`、网络、LLM Key**
。
-
测试必须自包含:
`conftest.py`
已隔离(
`RECRUITMENT_SKIP_ENV_FILES=1`
+ 临时 SQLite/目录),
**禁止依赖真实 `.env`、网络、LLM Key**
。
-
新增测试放
`backend/tests/`
,用
`client`
fixture(开放模式);
**改认证/权限/工作区逻辑时同步更新 `test_auth.py`**
(其
`auth_client`
fixture 设置了
`ADMIN_PASSWORD`
等,需模拟登录拿 token)。
-
新增测试放
`backend/tests/`
,用
`client`
fixture(开放模式);
**改认证/权限/工作区逻辑时同步更新 `test_auth.py`**
(其
`auth_client`
fixture 设置了
`ADMIN_PASSWORD`
等,需模拟登录拿 token)。
-
改动访谈题单/状态机时同步更新
`test_ai.py`
。
-
改动访谈题单/状态机时同步更新
`test_ai.py`
。
...
@@ -94,6 +94,6 @@
...
@@ -94,6 +94,6 @@
-
后端命令一律走
`backend/.venv`
,否则可能因缺依赖或版本不符失败。
-
后端命令一律走
`backend/.venv`
,否则可能因缺依赖或版本不符失败。
-
字段命名:前端 camelCase ↔ 后端 DB 列 snake_case;
`data`
列存整个实体 JSON(camelCase)——两边别混用。
-
字段命名:前端 camelCase ↔ 后端 DB 列 snake_case;
`data`
列存整个实体 JSON(camelCase)——两边别混用。
-
时间统一 ISO 字符串(
`utc_now_iso`
);ID 用
`前缀-uuid`
形式(job-、cand-、offer-、task-、evt-…);用户 ID 用
`usr-<username>`
。
-
时间统一 ISO 字符串(
`utc_now_iso`
);ID 用
`前缀-uuid`
形式(job-、cand-、offer-、task-、evt-…);用户 ID 用
`usr-<username>`
。
-
改
`models.py`
后:本地开发
由
`create_all`
自动建表,
**不需要**
手写迁移;正式迁移需
`alembic revision`
(对齐
`0001_initial`
全量建表风格)。
**给已有业务表加 `owner_id` 时**
会走
[
db.py 的 `_refresh_schema_for_owner_columns`
](
backend/app/db.py
)
自动补列回填
`local`
,注意保持该函数与新模型一致
。
-
改
`models.py`
后:本地开发
与全新部署均由
`create_all`
按当前模型建表,
**不需要**
手写迁移,也
**不兼容**
旧库结构;正式版本升级如需迁移,再新增 Alembic revision
。
-
登录模式:设置
`ADMIN_PASSWORD`
后首次启动自动建管理员(
`_ensure_admin`
);测试/脚本用
`RECRUITMENT_SKIP_ENV_FILES=1`
时会跳过 .env,需显式设 env 变量。
-
登录模式:设置
`ADMIN_PASSWORD`
后首次启动自动建管理员(
`_ensure_admin`
);测试/脚本用
`RECRUITMENT_SKIP_ENV_FILES=1`
时会跳过 .env,需显式设 env 变量。
-
文件必须 UTF-8;Windows 环境注意路径分隔(代码内用 pathlib,命令用反斜杠)。
-
文件必须 UTF-8;Windows 环境注意路径分隔(代码内用 pathlib,命令用反斜杠)。
README.md
View file @
4dc0dc3a
...
@@ -125,8 +125,8 @@ backend\.venv\Scripts\python.exe backend/scripts/start_server.py --with-frontend
...
@@ -125,8 +125,8 @@ backend\.venv\Scripts\python.exe backend/scripts/start_server.py --with-frontend
backend\.venv\Scripts\python.exe backend/scripts/create_user.py reset alice --password newpass123
backend\.venv\Scripts\python.exe backend/scripts/create_user.py reset alice --password newpass123
backend\.venv\Scripts\python.exe backend/scripts/create_user.py disable alice
backend\.venv\Scripts\python.exe backend/scripts/create_user.py disable alice
```
```
-
**
旧版兼容
**
:登录接口仍是
`P
OST /api/auth/login
`
返回 Bearer 令牌;同时保留
`A
DMIN_PASSWORD
`
的 Basic 认证作为兼容
通道
(
任意用户名 + 密码
)
。
-
**
接口兼容
**
:登录接口为
`P
OST /api/auth/login
`
返回 Bearer 令牌;同时保留
`A
DMIN_PASSWORD
`
的 Basic 认证
通道
(
任意用户名 + 密码
)
。
-
**
已有数据迁移
**
:旧库首次启动会自动为业务表补
`o
wner_id
`
列并归入
`l
ocal
`
工作区
(
开放模式下页面仍读
`l
ocal
`,
数据不丢
)
。
-
**
数据库基线
**
:新部署直接按当前 ORM 模型创建 16 张表,不读取、不修复、不迁移历史库结构
。
## 主要功能
## 主要功能
...
@@ -201,7 +201,7 @@ backend\.venv\Scripts\python.exe backend/scripts/start_server.py --with-frontend
...
@@ -201,7 +201,7 @@ backend\.venv\Scripts\python.exe backend/scripts/start_server.py --with-frontend
## 数据库迁移
## 数据库迁移
项目默认
`c
reate_all
`
自动建表;已有 Alembic 迁移支持,需要
时执行:
项目默认
由
`c
reate_all
`
按当前模型自动建表;新部署不需要执行迁移,也不兼容历史数据库结构。需要版本化建表
时执行:
```
powershell
```
powershell
backend
\.
venv
\S
cripts
\p
ython.exe -m alembic -c backend/alembic.ini upgrade head
backend
\.
venv
\S
cripts
\p
ython.exe -m alembic -c backend/alembic.ini upgrade head
...
...
backend/alembic/versions/0002_resume_evaluations.py
deleted
100644 → 0
View file @
d5234f7f
"""add immutable resume evaluation snapshots
Revision ID: 0002_resume_evaluations
Revises: 0001_initial
Create Date: 2026-09-22
"""
from
backend.app.models
import
ResumeEvaluation
from
alembic
import
op
revision
=
"0002_resume_evaluations"
down_revision
=
"0001_initial"
branch_labels
=
None
depends_on
=
None
def
upgrade
()
->
None
:
bind
=
op
.
get_bind
()
ResumeEvaluation
.
__table__
.
create
(
bind
=
bind
,
checkfirst
=
True
)
def
downgrade
()
->
None
:
bind
=
op
.
get_bind
()
ResumeEvaluation
.
__table__
.
drop
(
bind
=
bind
,
checkfirst
=
True
)
backend/app/db.py
View file @
4dc0dc3a
...
@@ -48,177 +48,7 @@ def get_db() -> Generator[Session, None, None]:
...
@@ -48,177 +48,7 @@ def get_db() -> Generator[Session, None, None]:
db
.
close
()
db
.
close
()
def
_refresh_schema_for_owner_columns
()
->
None
:
"""旧库升级:为业务表补 owner_id 列并回填 "local"。
多用户改造前,业务表没有 owner_id;改造后该列不可空且有默认语义
(开放模式的历史数据归 local 工作区)。SQLite 支持 ADD COLUMN 加带默认值的
NOT NULL 列,故直接补列 + 建索引即可保留全部现有数据。
"""
from
sqlalchemy
import
inspect
,
text
inspector
=
inspect
(
engine
)
table_names
=
set
(
inspector
.
get_table_names
())
if
not
table_names
:
return
for
name
in
_owner_column_tables
():
if
name
not
in
table_names
:
continue
columns
=
{
col
[
"name"
]
for
col
in
inspector
.
get_columns
(
name
)}
if
"owner_id"
not
in
columns
:
with
engine
.
begin
()
as
conn
:
conn
.
execute
(
text
(
f
"ALTER TABLE {name} ADD COLUMN owner_id VARCHAR(80) NOT NULL DEFAULT 'local'"
))
conn
.
execute
(
text
(
f
"CREATE INDEX IF NOT EXISTS ix_{name}_owner_id ON {name} (owner_id)"
))
# users 旧表缺 username 且无法 ADD COLUMN 加唯一约束:仅在确认无数据时 DROP 重建
if
"users"
in
table_names
:
columns
=
{
col
[
"name"
]
for
col
in
inspector
.
get_columns
(
"users"
)}
if
"username"
not
in
columns
:
with
engine
.
connect
()
as
conn
:
count
=
conn
.
scalar
(
text
(
"SELECT COUNT(*) FROM users"
))
if
count
:
raise
RuntimeError
(
"检测到旧版 users 表且已有数据,无法自动迁移。请先导出数据后删除 "
"data/recruitment.sqlite 重建(多用户改造前 users 表从不写入,正常不会触发此错误)。"
)
with
engine
.
begin
()
as
conn
:
conn
.
execute
(
text
(
"DROP TABLE users"
))
# app_state_meta 主键由 Integer(固定 id=1)改为 String(owner 用户名):
# 旧结构 id 为 INTEGER,raw_snapshot 只是业务表的冗余快照缓存,直接 DROP 后
# 由 create_all 按新结构重建,业务数据不受影响。
if
"app_state_meta"
in
table_names
:
id_type
=
""
for
col
in
inspector
.
get_columns
(
"app_state_meta"
):
if
col
[
"name"
]
==
"id"
:
id_type
=
str
(
col
[
"type"
])
.
upper
()
break
if
id_type
.
startswith
(
"INT"
):
with
engine
.
begin
()
as
conn
:
conn
.
execute
(
text
(
"DROP TABLE app_state_meta"
))
# 旧库升级:模型早已去掉 offers.candidate_id 的 UNIQUE(允许多条 Offer),
# 但 SQLite 不会自动删除已存在表上的约束,需重建表补齐。
_drop_offer_candidate_unique
()
def
_drop_offer_candidate_unique
()
->
None
:
"""移除旧 offers 表残留的 UNIQUE(candidate_id) 约束。
背景:早期 Offer.candidate_id 带 unique=True;后续允许「同一候选人多条 Offer
(一条进行中 + 历史已拒绝/已作废)」后模型已去掉该约束(见 backend/app/models.py 的 Offer)。
但 SQLite 不会自动改造已存在的表,导致 replace_state 写入多条同候选人 Offer 时报
UNIQUE constraint failed。SQLite 不支持 DROP CONSTRAINT,只能重建表。
仅当检测到该约束存在时才重建,幂等。
"""
if
engine
.
url
.
get_backend_name
()
!=
"sqlite"
:
return
from
sqlalchemy
import
inspect
inspector
=
inspect
(
engine
)
if
"offers"
not
in
inspector
.
get_table_names
():
return
if
not
any
(
uc
.
get
(
"column_names"
)
==
[
"candidate_id"
]
for
uc
in
inspector
.
get_unique_constraints
(
"offers"
)):
return
_rebuild_offers_without_unique
()
def
_rebuild_offers_without_unique
()
->
None
:
"""重建 offers 表以移除多余 UNIQUE(candidate_id),保留全部数据与索引。
重建期间临时关闭外键约束,避免 tasks.offer_id 等子表引用在 DROP/重建期间被改写;
列结构与 backend/app/models.py 的 Offer.__table__ 保持一致(无 unique),
owner_id 索引照旧重建。数据按列名拷贝,候选人与 Offer 的关联不受影响。
"""
raw
=
engine
.
raw_connection
()
try
:
raw_conn
=
raw
.
driver_connection
prev_isolation
=
raw_conn
.
isolation_level
raw_conn
.
isolation_level
=
None
cur
=
raw
.
cursor
()
cur
.
execute
(
"PRAGMA foreign_keys=OFF"
)
cur
.
execute
(
"BEGIN"
)
try
:
cur
.
execute
(
"""
CREATE TABLE offers_new (
id VARCHAR(120) NOT NULL,
owner_id VARCHAR(80) NOT NULL,
candidate_id VARCHAR(80) NOT NULL,
status VARCHAR(80),
salary VARCHAR(120),
start_date VARCHAR(80),
risk VARCHAR(80),
data TEXT NOT NULL,
created_at VARCHAR(40) NOT NULL,
updated_at VARCHAR(40) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY(candidate_id) REFERENCES candidates (id) ON DELETE CASCADE
)
"""
)
cur
.
execute
(
"""
INSERT INTO offers_new
(id, owner_id, candidate_id, status, salary, start_date, risk, data, created_at, updated_at)
SELECT id, owner_id, candidate_id, status, salary, start_date, risk, data, created_at, updated_at
FROM offers
"""
)
cur
.
execute
(
"DROP TABLE offers"
)
cur
.
execute
(
"ALTER TABLE offers_new RENAME TO offers"
)
cur
.
execute
(
"CREATE INDEX IF NOT EXISTS ix_offers_owner_id ON offers (owner_id)"
)
raw
.
commit
()
except
Exception
:
raw
.
rollback
()
raise
finally
:
cur
.
execute
(
"PRAGMA foreign_keys=ON"
)
cur
.
close
()
raw_conn
.
isolation_level
=
prev_isolation
finally
:
raw
.
close
()
def
_owner_column_tables
()
->
list
[
str
]:
from
backend.app.models
import
(
Candidate
,
CandidateApplication
,
CandidateMatchReport
,
IngestItem
,
Interview
,
JdVersion
,
Job
,
Offer
,
RecruitmentEvent
,
ResumeFile
,
ResumeProfile
,
ResumeText
,
Task
,
)
return
[
model
.
__tablename__
for
model
in
(
Job
,
JdVersion
,
Candidate
,
CandidateApplication
,
ResumeFile
,
ResumeText
,
ResumeProfile
,
CandidateMatchReport
,
Interview
,
Offer
,
Task
,
RecruitmentEvent
,
IngestItem
,
)
]
def
create_all
()
->
None
:
def
create_all
()
->
None
:
from
backend.app
import
models
# noqa: F401
from
backend.app
import
models
# noqa: F401
_refresh_schema_for_owner_columns
()
Base
.
metadata
.
create_all
(
bind
=
engine
)
Base
.
metadata
.
create_all
(
bind
=
engine
)
backend/app/models.py
View file @
4dc0dc3a
from
datetime
import
UTC
,
datetime
from
datetime
import
UTC
,
datetime
from
sqlalchemy
import
Boolean
,
ForeignKey
,
Index
,
Integer
,
String
,
Text
,
UniqueConstraint
from
sqlalchemy
import
Boolean
,
ForeignKey
,
Index
,
Integer
,
String
,
Text
from
sqlalchemy.orm
import
Mapped
,
mapped_column
from
sqlalchemy.orm
import
Mapped
,
mapped_column
from
backend.app.db
import
Base
from
backend.app.db
import
Base
...
@@ -10,13 +10,6 @@ def utc_now_iso() -> str:
...
@@ -10,13 +10,6 @@ def utc_now_iso() -> str:
return
datetime
.
now
(
UTC
)
.
isoformat
()
return
datetime
.
now
(
UTC
)
.
isoformat
()
class
SchemaMigration
(
Base
):
__tablename__
=
"schema_migrations"
version
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
)
applied_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
class
AppStateMeta
(
Base
):
class
AppStateMeta
(
Base
):
__tablename__
=
"app_state_meta"
__tablename__
=
"app_state_meta"
...
@@ -100,22 +93,6 @@ class Candidate(Base):
...
@@ -100,22 +93,6 @@ class Candidate(Base):
updated_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
updated_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
class
CandidateApplication
(
Base
):
__tablename__
=
"candidate_applications"
__table_args__
=
(
UniqueConstraint
(
"candidate_id"
,
"job_id"
,
name
=
"uq_candidate_application"
),)
id
:
Mapped
[
str
]
=
mapped_column
(
String
(
160
),
primary_key
=
True
)
owner_id
:
Mapped
[
str
]
=
mapped_column
(
String
(
80
),
nullable
=
False
,
index
=
True
)
candidate_id
:
Mapped
[
str
]
=
mapped_column
(
ForeignKey
(
"candidates.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
)
job_id
:
Mapped
[
str
|
None
]
=
mapped_column
(
ForeignKey
(
"jobs.id"
,
ondelete
=
"SET NULL"
))
stage
:
Mapped
[
str
|
None
]
=
mapped_column
(
String
(
80
))
status
:
Mapped
[
str
|
None
]
=
mapped_column
(
String
(
80
))
source
:
Mapped
[
str
|
None
]
=
mapped_column
(
String
(
80
))
data
:
Mapped
[
str
]
=
mapped_column
(
Text
,
nullable
=
False
)
created_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
updated_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
class
ResumeFile
(
Base
):
class
ResumeFile
(
Base
):
__tablename__
=
"resume_files"
__tablename__
=
"resume_files"
...
@@ -161,38 +138,6 @@ class ResumeProfile(Base):
...
@@ -161,38 +138,6 @@ class ResumeProfile(Base):
created_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
created_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
class
CandidateMatchReport
(
Base
):
__tablename__
=
"candidate_match_reports"
id
:
Mapped
[
str
]
=
mapped_column
(
String
(
120
),
primary_key
=
True
)
owner_id
:
Mapped
[
str
]
=
mapped_column
(
String
(
80
),
nullable
=
False
,
index
=
True
)
candidate_id
:
Mapped
[
str
]
=
mapped_column
(
ForeignKey
(
"candidates.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
)
job_id
:
Mapped
[
str
|
None
]
=
mapped_column
(
ForeignKey
(
"jobs.id"
,
ondelete
=
"SET NULL"
))
resume_profile_id
:
Mapped
[
str
|
None
]
=
mapped_column
(
ForeignKey
(
"resume_profiles.id"
,
ondelete
=
"SET NULL"
))
score
:
Mapped
[
int
|
None
]
=
mapped_column
(
Integer
)
segment
:
Mapped
[
str
|
None
]
=
mapped_column
(
String
(
80
))
status
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
"generated"
,
nullable
=
False
)
report_json
:
Mapped
[
str
]
=
mapped_column
(
Text
,
nullable
=
False
)
generated_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
class
Interview
(
Base
):
__tablename__
=
"interviews"
id
:
Mapped
[
str
]
=
mapped_column
(
String
(
120
),
primary_key
=
True
)
owner_id
:
Mapped
[
str
]
=
mapped_column
(
String
(
80
),
nullable
=
False
,
index
=
True
)
candidate_id
:
Mapped
[
str
]
=
mapped_column
(
ForeignKey
(
"candidates.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
)
job_id
:
Mapped
[
str
|
None
]
=
mapped_column
(
ForeignKey
(
"jobs.id"
,
ondelete
=
"SET NULL"
))
round
:
Mapped
[
str
|
None
]
=
mapped_column
(
String
(
80
))
scheduled_at
:
Mapped
[
str
|
None
]
=
mapped_column
(
String
(
80
))
interviewer
:
Mapped
[
str
|
None
]
=
mapped_column
(
String
(
120
))
result
:
Mapped
[
str
|
None
]
=
mapped_column
(
String
(
80
))
feedback
:
Mapped
[
str
|
None
]
=
mapped_column
(
Text
)
data
:
Mapped
[
str
]
=
mapped_column
(
Text
,
default
=
"{}"
,
nullable
=
False
)
created_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
updated_at
:
Mapped
[
str
]
=
mapped_column
(
String
(
40
),
default
=
utc_now_iso
,
nullable
=
False
)
class
Offer
(
Base
):
class
Offer
(
Base
):
__tablename__
=
"offers"
__tablename__
=
"offers"
...
...
backend/app/repositories/state_repository.py
View file @
4dc0dc3a
...
@@ -7,10 +7,7 @@ from sqlalchemy.orm import Session
...
@@ -7,10 +7,7 @@ from sqlalchemy.orm import Session
from
backend.app.models
import
(
from
backend.app.models
import
(
AppStateMeta
,
AppStateMeta
,
Candidate
,
Candidate
,
CandidateApplication
,
CandidateMatchReport
,
IngestItem
,
IngestItem
,
Interview
,
JdVersion
,
JdVersion
,
Job
,
Job
,
Offer
,
Offer
,
...
@@ -36,16 +33,13 @@ EMPTY_STATE: dict[str, Any] = {
...
@@ -36,16 +33,13 @@ EMPTY_STATE: dict[str, Any] = {
# 注意: CandidateReport(ADR 0002) 与 users / 人才池行级机制一样,刻意**不进**整包同步,
# 注意: CandidateReport(ADR 0002) 与 users / 人才池行级机制一样,刻意**不进**整包同步,
# 请勿把该表加入此列表,否则每次前端保存都会把分享报告清空。
# 请勿把该表加入此列表,否则每次前端保存都会把分享报告清空。
_OWNERED_MODELS
=
(
_OWNERED_MODELS
=
(
CandidateMatchReport
,
ResumeProfile
,
ResumeProfile
,
ResumeText
,
ResumeText
,
ResumeFile
,
ResumeFile
,
CandidateApplication
,
RecruitmentEvent
,
RecruitmentEvent
,
Task
,
Task
,
Offer
,
Offer
,
Candidate
,
Candidate
,
Interview
,
JdVersion
,
JdVersion
,
IngestItem
,
IngestItem
,
Job
,
Job
,
...
@@ -241,27 +235,6 @@ def replace_state(session: Session, owner: str, input_state: dict[str, Any], imp
...
@@ -241,27 +235,6 @@ def replace_state(session: Session, owner: str, input_state: dict[str, Any], imp
updated_at
=
state
[
"updatedAt"
],
updated_at
=
state
[
"updatedAt"
],
)
)
)
)
if
candidate
.
get
(
"jobId"
):
session
.
add
(
CandidateApplication
(
id
=
f
"{candidate_id}-{candidate['jobId']}"
,
owner_id
=
owner
,
candidate_id
=
candidate_id
,
job_id
=
candidate
[
"jobId"
],
stage
=
candidate
.
get
(
"stage"
)
or
""
,
status
=
candidate
.
get
(
"stage"
)
or
""
,
source
=
candidate
.
get
(
"source"
)
or
""
,
data
=
dump_json
(
{
"candidateId"
:
candidate_id
,
"jobId"
:
candidate
[
"jobId"
],
"stage"
:
candidate
.
get
(
"stage"
)
or
""
,
}
),
created_at
=
created_at
,
updated_at
=
state
[
"updatedAt"
],
)
)
session
.
flush
()
session
.
flush
()
for
offer
in
state
[
"offers"
]:
for
offer
in
state
[
"offers"
]:
...
...
qwenpaw
@
fef7e64d
Subproject commit fef7e64d984f4332d0b84a343cd209bd3ea5d316
backend/scripts/start_server.py
View file @
4dc0dc3a
...
@@ -86,8 +86,7 @@ def main(argv: list[str] | None = None) -> int:
...
@@ -86,8 +86,7 @@ def main(argv: list[str] | None = None) -> int:
uvicorn
.
run
(
uvicorn
.
run
(
"backend.app.main:app"
,
"backend.app.main:app"
,
# host=host,
host
=
host
,
host
=
"0.0.0.0"
,
port
=
port
,
port
=
port
,
reload
=
args
.
reload
,
reload
=
args
.
reload
,
reload_dirs
=
[
str
(
BACKEND_DIR
)]
if
args
.
reload
else
None
,
reload_dirs
=
[
str
(
BACKEND_DIR
)]
if
args
.
reload
else
None
,
...
@@ -96,6 +95,4 @@ def main(argv: list[str] | None = None) -> int:
...
@@ -96,6 +95,4 @@ def main(argv: list[str] | None = None) -> int:
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
import
sys
sys
.
argv
.
append
(
"--reload"
)
raise
SystemExit
(
main
())
raise
SystemExit
(
main
())
backend/tests/test_state.py
View file @
4dc0dc3a
...
@@ -51,79 +51,6 @@ def test_put_state_allows_multiple_offers_per_candidate(client):
...
@@ -51,79 +51,6 @@ def test_put_state_allows_multiple_offers_per_candidate(client):
assert
len
(
response
.
json
()[
"state"
][
"offers"
])
==
2
assert
len
(
response
.
json
()[
"state"
][
"offers"
])
==
2
def
test_legacy_offer_unique_constraint_is_dropped_on_startup
(
tmp_path
,
monkeypatch
):
"""旧库 offers 表残留 UNIQUE(candidate_id) 时,启动 schema 刷新应自动重建表移除该约束。"""
import
sqlite3
from
sqlalchemy
import
inspect
db_path
=
tmp_path
/
"legacy.sqlite"
con
=
sqlite3
.
connect
(
db_path
)
con
.
execute
(
"""
CREATE TABLE offers (
id VARCHAR(120) NOT NULL PRIMARY KEY,
candidate_id VARCHAR(80) NOT NULL,
status VARCHAR(80),
salary VARCHAR(120),
start_date VARCHAR(80),
risk VARCHAR(80),
data TEXT NOT NULL,
created_at VARCHAR(40) NOT NULL,
updated_at VARCHAR(40) NOT NULL,
owner_id VARCHAR(80) NOT NULL DEFAULT 'local',
UNIQUE (candidate_id),
FOREIGN KEY(candidate_id) REFERENCES candidates (id) ON DELETE CASCADE
)
"""
)
con
.
execute
(
"INSERT INTO offers (id, candidate_id, status, salary, start_date, risk, data, created_at, updated_at, owner_id) "
"VALUES ('offer-legacy', 'cand-1', '待 HR 确认', '', '', '正常', '{}', '2026-01-01', '2026-01-01', 'test1')"
)
con
.
commit
()
con
.
close
()
monkeypatch
.
setenv
(
"RECRUITMENT_SKIP_ENV_FILES"
,
"1"
)
monkeypatch
.
setenv
(
"DATABASE_URL"
,
f
"sqlite:///{db_path.as_posix()}"
)
monkeypatch
.
setenv
(
"DATA_DIR"
,
str
(
tmp_path
/
"data"
))
monkeypatch
.
setenv
(
"FILES_DIR"
,
str
(
tmp_path
/
"uploads"
))
monkeypatch
.
setenv
(
"ADMIN_PASSWORD"
,
""
)
monkeypatch
.
setenv
(
"INGEST_TOKEN"
,
""
)
monkeypatch
.
setenv
(
"LLM_API_KEY"
,
""
)
monkeypatch
.
setenv
(
"DEEPSEEK_API_KEY"
,
""
)
monkeypatch
.
setenv
(
"OPENAI_API_KEY"
,
""
)
import
backend.app.config
as
config
import
backend.app.db
as
dbm
config
.
get_settings
.
cache_clear
()
dbm
.
engine
.
dispose
()
dbm
.
settings
=
config
.
get_settings
()
dbm
.
engine
=
dbm
.
create_engine
(
dbm
.
normalize_database_url
(
dbm
.
settings
.
database_url
),
connect_args
=
{
"check_same_thread"
:
False
},
future
=
True
,
)
dbm
.
SessionLocal
.
configure
(
bind
=
dbm
.
engine
)
insp
=
inspect
(
dbm
.
engine
)
assert
any
(
uc
.
get
(
"column_names"
)
==
[
"candidate_id"
]
for
uc
in
insp
.
get_unique_constraints
(
"offers"
))
dbm
.
create_all
()
insp
=
inspect
(
dbm
.
engine
)
assert
not
any
(
uc
.
get
(
"column_names"
)
==
[
"candidate_id"
]
for
uc
in
insp
.
get_unique_constraints
(
"offers"
))
con
=
sqlite3
.
connect
(
db_path
)
rows
=
con
.
execute
(
"SELECT id, candidate_id, owner_id FROM offers"
)
.
fetchall
()
con
.
close
()
assert
rows
==
[(
"offer-legacy"
,
"cand-1"
,
"test1"
)]
dbm
.
engine
.
dispose
()
config
.
get_settings
.
cache_clear
()
def
_fk_enabled_session
(
tmp_path
):
def
_fk_enabled_session
(
tmp_path
):
"""自建一个开启 SQLite 外键约束的会话(conftest 的夹具引擎未开 PRAGMA,
"""自建一个开启 SQLite 外键约束的会话(conftest 的夹具引擎未开 PRAGMA,
否则测不出 replace_state 的外键序问题)。"""
否则测不出 replace_state 的外键序问题)。"""
...
...
docs/project_handoff.md
View file @
4dc0dc3a
...
@@ -76,7 +76,7 @@ recruit-sys/
...
@@ -76,7 +76,7 @@ recruit-sys/
│ ├── app/
│ ├── app/
│ │ ├── main.py # 应用工厂:CORS、认证中间件、admin 引导、路由挂载、静态托管、异常处理
│ │ ├── main.py # 应用工厂:CORS、认证中间件、admin 引导、路由挂载、静态托管、异常处理
│ │ ├── config.py # Settings(.env / .env.local 读取,Pydantic)
│ │ ├── config.py # Settings(.env / .env.local 读取,Pydantic)
│ │ ├── db.py # SQLAlchemy engine/session,
create_all 自动建表 + 旧库 owner_id 升级
│ │ ├── db.py # SQLAlchemy engine/session,
按当前模型 create_all 自动建表
│ │ ├── models.py # 16 张表 ORM 模型(业务表全部带 owner_id)
│ │ ├── models.py # 16 张表 ORM 模型(业务表全部带 owner_id)
│ │ ├── security.py # 认证中间件(Bearer 令牌 + Basic 兼容)+ ingest token 校验
│ │ ├── security.py # 认证中间件(Bearer 令牌 + Basic 兼容)+ ingest token 校验
│ │ ├── dependencies.py # 认证/角色/工作区依赖注入(get_current_user/require_admin/resolve_owner)
│ │ ├── dependencies.py # 认证/角色/工作区依赖注入(get_current_user/require_admin/resolve_owner)
...
@@ -124,7 +124,7 @@ recruit-sys/
...
@@ -124,7 +124,7 @@ recruit-sys/
### 4.2 数据模型与状态同步机制(重点)
### 4.2 数据模型与状态同步机制(重点)
-
全库共 16 张表(
[
models.py
](
backend/app/models.py
)
):
SchemaMigration、AppStateMeta、User、Job、JdVersion、Candidate、CandidateApplication、ResumeFile、ResumeText、ResumeProfile、CandidateMatchReport、Interview、Offer、Task、RecruitmentEvent、IngestIte
m。
-
全库共 16 张表(
[
models.py
](
backend/app/models.py
)
):
AppStateMeta、User、Job、JdVersion、Candidate、ResumeFile、ResumeText、ResumeProfile、Offer、Task、RecruitmentEvent、IngestItem、CandidateReport、ResumeParseTask、ResumeEvaluation、ExternalJobClai
m。
-
**多用户与工作区隔离**
:全部业务表带
`owner_id`
(归属用户名);
`AppStateMeta.id`
即工作区键(多用户下为用户名,开放模式为
`local`
)。
`User`
表存
`username`
(唯一)/
`role`
(admin|user)/
`password_hash`
(PBKDF2)/
`is_active`
/
`last_login_at`
,登录令牌为 HMAC-SHA256(SESSION_SECRET) 签名的无状态 Bearer 令牌(见
[
services/auth_security.py
](
backend/app/services/auth_security.py
)
)。
-
**多用户与工作区隔离**
:全部业务表带
`owner_id`
(归属用户名);
`AppStateMeta.id`
即工作区键(多用户下为用户名,开放模式为
`local`
)。
`User`
表存
`username`
(唯一)/
`role`
(admin|user)/
`password_hash`
(PBKDF2)/
`is_active`
/
`last_login_at`
,登录令牌为 HMAC-SHA256(SESSION_SECRET) 签名的无状态 Bearer 令牌(见
[
services/auth_security.py
](
backend/app/services/auth_security.py
)
)。
-
**核心机制**
:业务数据以「整包 JSON 状态」为事实源。
`GET /api/state`
把当前 owner 的各表读回合并为一个
`{jobs, candidates, offers, tasks, eventLog, updatedAt}`
对象;
`PUT /api/state`
则先按 owner 清空再全量重写。
`AppStateMeta.raw_snapshot`
存整包快照,供无数据时回读。
-
**核心机制**
:业务数据以「整包 JSON 状态」为事实源。
`GET /api/state`
把当前 owner 的各表读回合并为一个
`{jobs, candidates, offers, tasks, eventLog, updatedAt}`
对象;
`PUT /api/state`
则先按 owner 清空再全量重写。
`AppStateMeta.raw_snapshot`
存整包快照,供无数据时回读。
-
这意味着:
**这不是增量/事件溯源架构,而是「快照全量替换」**
。同一工作区内多端并发写会互相覆盖(last-write-wins);不同用户之间通过
`owner_id`
天然隔离。
-
这意味着:
**这不是增量/事件溯源架构,而是「快照全量替换」**
。同一工作区内多端并发写会互相覆盖(last-write-wins);不同用户之间通过
`owner_id`
天然隔离。
...
@@ -211,7 +211,7 @@ backend\.venv\Scripts\python.exe backend/scripts/start_server.py --with-frontend
...
@@ -211,7 +211,7 @@ backend\.venv\Scripts\python.exe backend/scripts/start_server.py --with-frontend
-
**角色**
:
`admin`
(用户管理 + 全部工作区读写)/
`user`
(自己工作区读写)。用户管理入口在侧边栏「用户管理」(仅 admin 可见)。
-
**角色**
:
`admin`
(用户管理 + 全部工作区读写)/
`user`
(自己工作区读写)。用户管理入口在侧边栏「用户管理」(仅 admin 可见)。
-
**工作区隔离**
:普通用户只能读写自己的工作区(
`?owner=`
越权返回 403);admin 可在顶栏工作区下拉切换查看/操作任意用户数据。
-
**工作区隔离**
:普通用户只能读写自己的工作区(
`?owner=`
越权返回 403);admin 可在顶栏工作区下拉切换查看/操作任意用户数据。
-
**用户管理 CLI**
(无界面场景):
`backend/scripts/create_user.py`
,支持
`create`
/
`list`
/
`reset`
/
`disable`
/
`enable`
(见 README §5)。
-
**用户管理 CLI**
(无界面场景):
`backend/scripts/create_user.py`
,支持
`create`
/
`list`
/
`reset`
/
`disable`
/
`enable`
(见 README §5)。
-
**
旧库升级**
:旧版 SQLite 首次启动自动为业务表补
`owner_id`
列并回填
`local`
、重建
`users`
/
`app_state_meta`
(无数据时),历史数据不丢(见
[
db.py 的 `_refresh_schema_for_owner_columns`
](
backend/app/db.py
)
)
。
-
**
数据库基线**
:新部署直接使用空库,由
`create_all`
按当前模型创建 16 张表;代码不读取、不修复、不迁移历史库结构
。
### 5.5 启动前端(开发模式)
### 5.5 启动前端(开发模式)
...
@@ -318,7 +318,7 @@ backend\.venv\Scripts\python.exe -m pytest -c backend/pyproject.toml
...
@@ -318,7 +318,7 @@ backend\.venv\Scripts\python.exe -m pytest -c backend/pyproject.toml
7.
**部署文档化**
:补一份部署检查单(改密码/secret/token、数据目录外置、备份策略),把 §8.3 的注意事项固化为流程。
7.
**部署文档化**
:补一份部署检查单(改密码/secret/token、数据目录外置、备份策略),把 §8.3 的注意事项固化为流程。
8.
**前端构建依赖**
:
`start_server.py --with-frontend`
依赖
`vue-app/node_modules`
(已 gitignore),新机器首次需先
`cd vue-app && npm install`
;脚本已给出明确报错提示。
8.
**前端构建依赖**
:
`start_server.py --with-frontend`
依赖
`vue-app/node_modules`
(已 gitignore),新机器首次需先
`cd vue-app && npm install`
;脚本已给出明确报错提示。
> 已完成的修复:启动脚本统一(`backend/scripts/start_server.py`,删除 `backend/package.json` 与失效脚本 `sync_frontend_static.py`/`legacy-server.mjs`);静态托管链路(`--with-frontend` 构建+同步);词典去重(前后端共享 `shared/resume-dictionaries.json`);测试断言更新为 Vue 前端资源;**多用户登录 + 按用户隔离工作区 + 用户管理 + 认证中间件(Bearer/Basic 兼容)+ 用户管理 CLI(`create_user.py`)
+ 旧库自动升级**(后端测试 25
过 0 挂)。
> 已完成的修复:启动脚本统一(`backend/scripts/start_server.py`,删除 `backend/package.json` 与失效脚本 `sync_frontend_static.py`/`legacy-server.mjs`);静态托管链路(`--with-frontend` 构建+同步);词典去重(前后端共享 `shared/resume-dictionaries.json`);测试断言更新为 Vue 前端资源;**多用户登录 + 按用户隔离工作区 + 用户管理 + 认证中间件(Bearer/Basic 兼容)+ 用户管理 CLI(`create_user.py`)
**(后端测试 138
过 0 挂)。
---
---
...
@@ -328,7 +328,7 @@ backend\.venv\Scripts\python.exe -m pytest -c backend/pyproject.toml
...
@@ -328,7 +328,7 @@ backend\.venv\Scripts\python.exe -m pytest -c backend/pyproject.toml
| --- | --- |
| --- | --- |
| 应用入口 / 路由挂载 / 中间件 / admin 引导 |
[
backend/app/main.py
](
backend/app/main.py
)
|
| 应用入口 / 路由挂载 / 中间件 / admin 引导 |
[
backend/app/main.py
](
backend/app/main.py
)
|
| 配置与 env 读取 |
[
backend/app/config.py
](
backend/app/config.py
)
|
| 配置与 env 读取 |
[
backend/app/config.py
](
backend/app/config.py
)
|
| 数据库与
自动建表 + 旧库 owner_id 升级
|
[
backend/app/db.py
](
backend/app/db.py
)
|
| 数据库与
当前模型自动建表
|
[
backend/app/db.py
](
backend/app/db.py
)
|
| ORM 模型(16 表,业务表带 owner_id) |
[
backend/app/models.py
](
backend/app/models.py
)
|
| ORM 模型(16 表,业务表带 owner_id) |
[
backend/app/models.py
](
backend/app/models.py
)
|
| 认证中间件(Bearer 令牌 + Basic 兼容)/ 采集令牌 |
[
backend/app/security.py
](
backend/app/security.py
)
|
| 认证中间件(Bearer 令牌 + Basic 兼容)/ 采集令牌 |
[
backend/app/security.py
](
backend/app/security.py
)
|
| 认证依赖注入(当前用户/角色/工作区) |
[
backend/app/dependencies.py
](
backend/app/dependencies.py
)
|
| 认证依赖注入(当前用户/角色/工作区) |
[
backend/app/dependencies.py
](
backend/app/dependencies.py
)
|
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment