签入版本

This commit is contained in:
2026-09-12 17:39:13 +08:00
parent 25c8b039ac
commit 3233d221b0
871 changed files with 103088 additions and 10561 deletions
+27
View File
@@ -0,0 +1,27 @@
"""scripts/init_db.py 的 Oracle 自增 SQL 生成器单测(与 migrate_db 对齐)。
Oracle create_all 不生成 Integer 主键自增,init_db 会补 sequence + BEFORE INSERT 触发器;
这里验证生成的 DDL 字符串正确(与 scripts/migrate_db.py 的既有实现一致)。
"""
import sys
from pathlib import Path
# scripts/ 下无 __init__.py,把 scripts 目录加进 sys.path 以便直接 import
_SCRIPTS_DIR = Path(__file__).resolve().parents[3] / "scripts"
if str(_SCRIPTS_DIR) not in sys.path:
sys.path.insert(0, str(_SCRIPTS_DIR))
import init_db # noqa: E402
def test_oracle_sequence_sql():
seq = init_db.oracle_sequence_sql("fastapi_user", 27)
assert seq == "CREATE SEQUENCE fastapi_user_id_seq START WITH 27 INCREMENT BY 1 NOCACHE"
def test_oracle_trigger_sql():
trg = init_db.oracle_trigger_sql("fastapi_user")
assert "BEFORE INSERT ON fastapi_user FOR EACH ROW" in trg
assert "WHEN (NEW.id IS NULL)" in trg
assert "SELECT fastapi_user_id_seq.NEXTVAL INTO :NEW.id FROM dual" in trg