fix(db): drop utcnow + atomic migrations + row factory test
This commit is contained in:
@@ -51,8 +51,11 @@ def migrate(conn: sqlite3.Connection) -> None:
|
||||
continue
|
||||
sql = sql_file.read_text(encoding="utf-8")
|
||||
with conn:
|
||||
conn.executescript(sql)
|
||||
for stmt in sql.split(";"):
|
||||
stmt = stmt.strip()
|
||||
if stmt:
|
||||
conn.execute(stmt)
|
||||
conn.execute(
|
||||
"INSERT INTO migrations(version, applied_at) VALUES(?, ?);",
|
||||
(version, _dt.datetime.utcnow().isoformat(timespec="seconds") + "Z"),
|
||||
(version, _dt.datetime.now(_dt.UTC).strftime("%Y-%m-%dT%H:%M:%SZ")),
|
||||
)
|
||||
|
||||
@@ -40,3 +40,20 @@ def test_get_connection_creates_parent_dir(tmp_path):
|
||||
conn = get_connection(target)
|
||||
assert target.parent.exists()
|
||||
conn.close()
|
||||
|
||||
|
||||
def test_get_connection_row_factory_supports_name_access(tmp_path):
|
||||
conn = get_connection(tmp_path / "row.db")
|
||||
conn.execute("CREATE TABLE t (val INTEGER);")
|
||||
conn.execute("INSERT INTO t VALUES (42);")
|
||||
row = conn.execute("SELECT val FROM t;").fetchone()
|
||||
assert row["val"] == 42
|
||||
conn.close()
|
||||
|
||||
|
||||
def test_resolve_db_path_falls_back_to_home(monkeypatch):
|
||||
from pathlib import Path
|
||||
monkeypatch.delenv("WP_DB_PATH", raising=False)
|
||||
monkeypatch.delenv("COMFYUI_USER_DIR", raising=False)
|
||||
result = resolve_db_path()
|
||||
assert result == Path.home() / ".comfyui" / "wildcard-pipeline.db"
|
||||
|
||||
Reference in New Issue
Block a user