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
89 changes: 87 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": "abdf5c23-7f2e-4ca3-b08b-012db47b5aa5",
"id": "7e8e00e9-7bbb-443e-996b-f646ec030c2b",
"prevIds": [
"442cdbd5-86a8-41a9-86d6-5361dbac90e0"
"cce2163c-da01-4239-86fa-776d48a58d89"
],
"ddl": [
{
Expand Down Expand Up @@ -50,6 +50,10 @@
"name": "event",
"entityType": "tables"
},
{
"name": "goal_outcome",
"entityType": "tables"
},
{
"name": "goal_state",
"entityType": "tables"
Expand Down Expand Up @@ -1018,6 +1022,46 @@
"entityType": "columns",
"table": "event"
},
{
"type": "text",
"notNull": false,
"autoincrement": false,
"default": null,
"generated": null,
"name": "goal_id",
"entityType": "columns",
"table": "goal_outcome"
},
{
"type": "text",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "session_id",
"entityType": "columns",
"table": "goal_outcome"
},
{
"type": "text",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "payload",
"entityType": "columns",
"table": "goal_outcome"
},
{
"type": "integer",
"notNull": true,
"autoincrement": false,
"default": null,
"generated": null,
"name": "completed_at",
"entityType": "columns",
"table": "goal_outcome"
},
{
"type": "text",
"notNull": false,
Expand Down Expand Up @@ -2364,6 +2408,15 @@
"table": "event",
"entityType": "pks"
},
{
"columns": [
"goal_id"
],
"nameExplicit": false,
"name": "goal_outcome_pk",
"table": "goal_outcome",
"entityType": "pks"
},
{
"columns": [
"session_id"
Expand Down Expand Up @@ -2640,6 +2693,24 @@
"entityType": "indexes",
"table": "event"
},
{
"columns": [
{
"value": "session_id",
"isExpression": false
},
{
"value": "completed_at",
"isExpression": false
}
],
"isUnique": false,
"where": null,
"origin": "manual",
"name": "goal_outcome_session_completed_idx",
"entityType": "indexes",
"table": "goal_outcome"
},
{
"columns": [
{
Expand Down Expand Up @@ -2910,6 +2981,20 @@
"entityType": "indexes",
"table": "session"
},
{
"columns": [
{
"value": "directory",
"isExpression": false
}
],
"isUnique": false,
"where": null,
"origin": "manual",
"name": "session_directory_idx",
"entityType": "indexes",
"table": "session"
},
{
"columns": [
{
Expand Down
2 changes: 2 additions & 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,21 @@
import { Effect } from "effect"
import type { DatabaseMigration } from "../migration"

export default {
id: "20260811060000_goal_outcome",
up(tx) {
return Effect.gen(function* () {
yield* tx.run(`
CREATE TABLE goal_outcome (
goal_id text PRIMARY KEY,
session_id text NOT NULL,
payload text NOT NULL,
completed_at integer NOT NULL
);
`)
yield* tx.run(
`CREATE INDEX goal_outcome_session_completed_idx ON goal_outcome (session_id, completed_at);`,
)
})
},
} satisfies DatabaseMigration.Migration
11 changes: 11 additions & 0 deletions packages/core/src/database/migration/20260813020344_bored_skaar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Effect } from "effect"
import type { DatabaseMigration } from "../migration"

export default {
id: "20260813020344_bored_skaar",
up(tx) {
return Effect.gen(function* () {
yield* tx.run(`CREATE INDEX \`session_directory_idx\` ON \`session\` (\`directory\`);`)
})
},
} satisfies DatabaseMigration.Migration
12 changes: 12 additions & 0 deletions packages/core/src/database/schema.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ export default {
CONSTRAINT \`fk_event_aggregate_id_event_sequence_aggregate_id_fk\` FOREIGN KEY (\`aggregate_id\`) REFERENCES \`event_sequence\`(\`aggregate_id\`) ON DELETE CASCADE
);
`)
yield* tx.run(`
CREATE TABLE \`goal_outcome\` (
\`goal_id\` text PRIMARY KEY,
\`session_id\` text NOT NULL,
\`payload\` text NOT NULL,
\`completed_at\` integer NOT NULL
);
`)
yield* tx.run(`
CREATE TABLE \`goal_state\` (
\`session_id\` text PRIMARY KEY,
Expand Down Expand Up @@ -323,6 +331,9 @@ export default {
)
yield* tx.run(`CREATE UNIQUE INDEX \`event_aggregate_seq_idx\` ON \`event\` (\`aggregate_id\`,\`seq\`);`)
yield* tx.run(`CREATE INDEX \`event_aggregate_type_seq_idx\` ON \`event\` (\`aggregate_id\`,\`type\`,\`seq\`);`)
yield* tx.run(
`CREATE INDEX \`goal_outcome_session_completed_idx\` ON \`goal_outcome\` (\`session_id\`,\`completed_at\`);`,
)
yield* tx.run(`CREATE INDEX \`goal_state_updated_at_idx\` ON \`goal_state\` (\`updated_at\`);`)
yield* tx.run(
`CREATE UNIQUE INDEX \`permission_project_action_resource_idx\` ON \`permission\` (\`project_id\`,\`action\`,\`resource\`);`,
Expand Down Expand Up @@ -354,6 +365,7 @@ export default {
yield* tx.run(`CREATE INDEX \`session_project_idx\` ON \`session\` (\`project_id\`);`)
yield* tx.run(`CREATE INDEX \`session_workspace_idx\` ON \`session\` (\`workspace_id\`);`)
yield* tx.run(`CREATE INDEX \`session_parent_idx\` ON \`session\` (\`parent_id\`);`)
yield* tx.run(`CREATE INDEX \`session_directory_idx\` ON \`session\` (\`directory\`);`)
yield* tx.run(`CREATE INDEX \`todo_session_idx\` ON \`todo\` (\`session_id\`);`)
})
},
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/goal/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ export const GoalStateTable = sqliteTable(
},
(t) => [index("goal_state_updated_at_idx").on(t.updated_at)],
)

export const GoalOutcomeTable = sqliteTable(
"goal_outcome",
{
goal_id: text().primaryKey(),
session_id: text().notNull(),
payload: text().notNull(),
completed_at: integer().notNull(),
},
(t) => [index("goal_outcome_session_completed_idx").on(t.session_id, t.completed_at)],
)
3 changes: 3 additions & 0 deletions packages/core/src/session/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const SessionTable = sqliteTable(
index("session_project_idx").on(table.project_id),
index("session_workspace_idx").on(table.workspace_id),
index("session_parent_idx").on(table.parent_id),
// GOAL-FP-01-04 (S-1): the GoalLoop startup scan joins goal_state →
// session and filters on session.directory on every instance boot.
index("session_directory_idx").on(table.directory),
],
)

Expand Down
Loading
Loading