Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 206 additions & 2 deletions packages/core/schema.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"version": "7",
"dialect": "sqlite",
"id": "68fc67ad-c3bd-4c0f-923d-db9817bf7475",
"id": "847009df-a964-45cd-b79f-6d07bf06e3e2",
"prevIds": [
"169b3aad-5dd0-4a14-a772-423b22ab2217"
"68fc67ad-c3bd-4c0f-923d-db9817bf7475"
],
"ddl": [
{
Expand Down Expand Up @@ -70,6 +70,14 @@
"name": "session_input",
"entityType": "tables"
},
{
"name": "session_lineage_origin",
"entityType": "tables"
},
{
"name": "session_lineage",
"entityType": "tables"
},
{
"name": "session_message",
"entityType": "tables"
Expand Down Expand Up @@ -1066,6 +1074,126 @@
"entityType": "columns",
"table": "session_input"
},
{
"type": "text",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "root_id",
"entityType": "columns",
"table": "session_lineage_origin"
},
{
"type": "text",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "session_id",
"entityType": "columns",
"table": "session_lineage_origin"
},
{
"type": "text",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "title",
"entityType": "columns",
"table": "session_lineage_origin"
},
{
"type": "text",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "edge_kind",
"entityType": "columns",
"table": "session_lineage_origin"
},
{
"type": "integer",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "deleted_at",
"entityType": "columns",
"table": "session_lineage_origin"
},
{
"type": "text",
"notNull": false,
"autoincrement": false,
"default": null,
"generated": null,
"name": "session_id",
"entityType": "columns",
"table": "session_lineage"
},
{
"type": "text",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "root_id",
"entityType": "columns",
"table": "session_lineage"
},
{
"type": "text",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "mode",
"entityType": "columns",
"table": "session_lineage"
},
{
"type": "text",
"notNull": false,
"autoincrement": false,
"default": null,
"generated": null,
"name": "parent_id",
"entityType": "columns",
"table": "session_lineage"
},
{
"type": "text",
"notNull": false,
"autoincrement": false,
"default": null,
"generated": null,
"name": "edge_kind",
"entityType": "columns",
"table": "session_lineage"
},
{
"type": "text",
"notNull": false,
"autoincrement": false,
"default": null,
"generated": null,
"name": "legacy_parent_id",
"entityType": "columns",
"table": "session_lineage"
},
{
"type": "integer",
"notNull": false,
"autoincrement": false,
"default": null,
"generated": null,
"name": "epoch_started_at",
"entityType": "columns",
"table": "session_lineage"
},
{
"type": "text",
"notNull": false,
Expand Down Expand Up @@ -1716,6 +1844,21 @@
"entityType": "fks",
"table": "session_input"
},
{
"columns": [
"session_id"
],
"tableTo": "session",
"columnsTo": [
"id"
],
"onUpdate": "NO ACTION",
"onDelete": "CASCADE",
"nameExplicit": false,
"name": "fk_session_lineage_session_id_session_id_fk",
"entityType": "fks",
"table": "session_lineage"
},
{
"columns": [
"session_id"
Expand Down Expand Up @@ -1796,6 +1939,16 @@
"entityType": "pks",
"table": "project_directory"
},
{
"columns": [
"root_id",
"session_id"
],
"nameExplicit": false,
"name": "session_lineage_origin_pk",
"entityType": "pks",
"table": "session_lineage_origin"
},
{
"columns": [
"session_id",
Expand Down Expand Up @@ -1932,6 +2085,15 @@
"table": "session_input",
"entityType": "pks"
},
{
"columns": [
"session_id"
],
"nameExplicit": false,
"name": "session_lineage_pk",
"table": "session_lineage",
"entityType": "pks"
},
{
"columns": [
"id"
Expand Down Expand Up @@ -2163,6 +2325,48 @@
"entityType": "indexes",
"table": "session_input"
},
{
"columns": [
{
"value": "root_id",
"isExpression": false
}
],
"isUnique": false,
"where": null,
"origin": "manual",
"name": "session_lineage_origin_root_idx",
"entityType": "indexes",
"table": "session_lineage_origin"
},
{
"columns": [
{
"value": "root_id",
"isExpression": false
}
],
"isUnique": false,
"where": null,
"origin": "manual",
"name": "session_lineage_root_idx",
"entityType": "indexes",
"table": "session_lineage"
},
{
"columns": [
{
"value": "parent_id",
"isExpression": false
}
],
"isUnique": false,
"where": null,
"origin": "manual",
"name": "session_lineage_parent_idx",
"entityType": "indexes",
"table": "session_lineage"
},
{
"columns": [
{
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const MERGE_TABLES = [
"event",
"permission",
"session",
"session_lineage",
"session_lineage_origin",
"session_message",
"session_input",
"session_context_epoch",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/database/migration.gen.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Effect } from "effect"
import type { DatabaseMigration } from "../migration"

export default {
id: "20260913205004_session-lineage",
up(tx) {
return Effect.gen(function* () {
yield* tx.run(`
CREATE TABLE \`session_lineage_origin\` (
\`root_id\` text NOT NULL,
\`session_id\` text NOT NULL,
\`title\` text NOT NULL,
\`edge_kind\` text NOT NULL,
\`deleted_at\` integer NOT NULL,
CONSTRAINT \`session_lineage_origin_pk\` PRIMARY KEY(\`root_id\`, \`session_id\`)
);
`)
yield* tx.run(`
CREATE TABLE \`session_lineage\` (
\`session_id\` text PRIMARY KEY,
\`root_id\` text NOT NULL,
\`mode\` text NOT NULL,
\`parent_id\` text,
\`edge_kind\` text,
\`legacy_parent_id\` text,
\`epoch_started_at\` integer,
CONSTRAINT \`fk_session_lineage_session_id_session_id_fk\` FOREIGN KEY (\`session_id\`) REFERENCES \`session\`(\`id\`) ON DELETE CASCADE
);
`)
yield* tx.run(`CREATE INDEX \`session_lineage_origin_root_idx\` ON \`session_lineage_origin\` (\`root_id\`);`)
yield* tx.run(`CREATE INDEX \`session_lineage_root_idx\` ON \`session_lineage\` (\`root_id\`);`)
yield* tx.run(`CREATE INDEX \`session_lineage_parent_idx\` ON \`session_lineage\` (\`parent_id\`);`)
})
},
} satisfies DatabaseMigration.Migration
25 changes: 25 additions & 0 deletions packages/core/src/database/schema.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,28 @@ export default {
CONSTRAINT \`fk_session_input_session_id_session_id_fk\` FOREIGN KEY (\`session_id\`) REFERENCES \`session\`(\`id\`) ON DELETE CASCADE
);
`)
yield* tx.run(`
CREATE TABLE \`session_lineage_origin\` (
\`root_id\` text NOT NULL,
\`session_id\` text NOT NULL,
\`title\` text NOT NULL,
\`edge_kind\` text NOT NULL,
\`deleted_at\` integer NOT NULL,
CONSTRAINT \`session_lineage_origin_pk\` PRIMARY KEY(\`root_id\`, \`session_id\`)
);
`)
yield* tx.run(`
CREATE TABLE \`session_lineage\` (
\`session_id\` text PRIMARY KEY,
\`root_id\` text NOT NULL,
\`mode\` text NOT NULL,
\`parent_id\` text,
\`edge_kind\` text,
\`legacy_parent_id\` text,
\`epoch_started_at\` integer,
CONSTRAINT \`fk_session_lineage_session_id_session_id_fk\` FOREIGN KEY (\`session_id\`) REFERENCES \`session\`(\`id\`) ON DELETE CASCADE
);
`)
yield* tx.run(`
CREATE TABLE \`session_message\` (
\`id\` text PRIMARY KEY,
Expand Down Expand Up @@ -271,6 +293,9 @@ export default {
yield* tx.run(
`CREATE UNIQUE INDEX \`session_input_session_promoted_seq_idx\` ON \`session_input\` (\`session_id\`,\`promoted_seq\`);`,
)
yield* tx.run(`CREATE INDEX \`session_lineage_origin_root_idx\` ON \`session_lineage_origin\` (\`root_id\`);`)
yield* tx.run(`CREATE INDEX \`session_lineage_root_idx\` ON \`session_lineage\` (\`root_id\`);`)
yield* tx.run(`CREATE INDEX \`session_lineage_parent_idx\` ON \`session_lineage\` (\`parent_id\`);`)
yield* tx.run(
`CREATE UNIQUE INDEX \`session_message_session_seq_idx\` ON \`session_message\` (\`session_id\`,\`seq\`);`,
)
Expand Down
43 changes: 43 additions & 0 deletions packages/core/src/session/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,49 @@ export const SessionTable = sqliteTable(
],
)

/**
* Durable Files Changed lineage. A missing row is deliberately meaningful: it
* denotes a pre-rollout (legacy) session, never an inferred relationship.
*/
export const SessionLineageTable = sqliteTable(
"session_lineage",
{
session_id: text()
.$type<SessionSchema.ID>()
.primaryKey()
.references(() => SessionTable.id, { onDelete: "cascade" }),
root_id: text().$type<SessionSchema.ID>().notNull(),
mode: text().$type<"legacy" | "partial" | "full">().notNull(),
parent_id: text().$type<SessionSchema.ID>(),
edge_kind: text().$type<"task_spawn" | "session_spawn">(),
legacy_parent_id: text().$type<SessionSchema.ID>(),
epoch_started_at: integer(),
},
(table) => [
index("session_lineage_root_idx").on(table.root_id),
index("session_lineage_parent_idx").on(table.parent_id),
],
)

/**
* The root-owned, deletion-safe minimum required to render historical Files
* Changed receipts. It intentionally excludes child context and evidence.
*/
export const SessionLineageOriginTable = sqliteTable(
"session_lineage_origin",
{
root_id: text().$type<SessionSchema.ID>().notNull(),
session_id: text().$type<SessionSchema.ID>().notNull(),
title: text().notNull(),
edge_kind: text().$type<"task_spawn" | "session_spawn">().notNull(),
deleted_at: integer().notNull(),
},
(table) => [
primaryKey({ columns: [table.root_id, table.session_id] }),
index("session_lineage_origin_root_idx").on(table.root_id),
],
)

export const MessageTable = sqliteTable(
"message",
{
Expand Down
Loading
Loading