Files
deepseek-harness/packages/session/session-persistence-sqlite/resources/sql/store/fork-attachment.sql
T
Magolor 6da7ed3f6e refactor(session): keep the SQLite store's SQL in versioned .sql resources
The schema and every static statement of the SQLite Session store were
string literals in TypeScript, and the upgrade step from the frame layout
executed whatever the current schema constant held. They now live under
resources/sql: schema/vN.sql is the whole schema of one version and is
not edited once released, upgrade/A-to-B holds the statements of one
upgrade step, and store/ and derived/ hold the statements of the store
and of the derived-table runtime. src/sql.ts is their only reader.

Two internal views, segment_extents and session_heads, replace the SQL
fragments the store shared by string interpolation. Transaction control,
connection pragmas and the DDL generated from a derivation stay inline.
2026-11-25 18:47:26 +08:00

7 lines
530 B
SQL

-- Finds the deepest ancestor that starts at or before a fork's cut; visible_end counts that ancestor's events
-- in the forked history. Binds: head segment_id of the forked Session, the Session sequence of the cut.
SELECT s.segment_id, s.segment_uuid, s.parent_id, s.base_seq, s.event_count, p.end_seq - s.base_seq AS visible_end
FROM segment_paths p JOIN segment_extents s ON s.segment_id = p.member_id
WHERE p.segment_id = ? AND p.member_id != p.segment_id AND s.base_seq <= ?
ORDER BY s.base_seq DESC, p.end_seq DESC LIMIT 1;