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
2 changes: 1 addition & 1 deletion apps/server/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const migrations = {
// What each space's daemons last published (git status, skills), mirrored from CodeWork's event
// stream: a stopped sandbox is shown from here, never woken.
yield* sql`
CREATE TABLE space_state (
CREATE TABLE machine_space_state (
machine_id TEXT NOT NULL,
space_id TEXT NOT NULL,
type TEXT NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const list = Effect.fn("Skills.list")(function* (
Effect.orElseSucceed(() => []),
);
const kept = yield* sql<{ spaceId: string; data: string; observedAt: number }>`
SELECT space_id, data, observed_at FROM space_state
SELECT space_id, data, observed_at FROM machine_space_state
WHERE machine_id = ${input.machineId} AND type = 'plugin.skills.list'
`.pipe(Effect.orDie);
return spaces.map((space): SpaceSkills => {
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export const layer = Layer.effect(
});

/**
* The builtin space daemons' events, into `space_state`. A subscription opens with each space's
* The builtin space daemons' events, into `machine_space_state`. A subscription opens with each space's
* last event: it is (re)started after an index batch mirrored spaces, so that replay finds their
* rows, and again whenever it fails or ends. Only a newer event replaces a row.
*/
Expand All @@ -276,12 +276,12 @@ export const layer = Layer.effect(
yield* transact((append) =>
Effect.gen(function* () {
const written = yield* sql<{ spaceId: string }>`
INSERT INTO space_state (machine_id, space_id, type, data, observed_at)
INSERT INTO machine_space_state (machine_id, space_id, type, data, observed_at)
SELECT ${machineId}, ${spaceId}, ${frame.type}, ${text}, ${observedAt}
WHERE EXISTS (SELECT 1 FROM space WHERE machine_id = ${machineId} AND id = ${spaceId})
ON CONFLICT (machine_id, space_id, type) DO UPDATE
SET data = excluded.data, observed_at = excluded.observed_at
WHERE space_state.observed_at < excluded.observed_at
WHERE machine_space_state.observed_at < excluded.observed_at
RETURNING space_id
`;
if (written.length === 0) return;
Expand Down
12 changes: 6 additions & 6 deletions apps/server/test/__artifacts__/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
"tbl_name": "machine",
"sql": "CREATE TABLE machine ( id TEXT PRIMARY KEY, kind TEXT NOT NULL, name TEXT NOT NULL, executable TEXT, home TEXT, args TEXT NOT NULL DEFAULT '', env TEXT NOT NULL DEFAULT '[]', url TEXT, namespace TEXT NOT NULL, is_default INTEGER NOT NULL DEFAULT 0, pos INTEGER NOT NULL, store_id TEXT UNIQUE, cursor INTEGER NOT NULL DEFAULT 0, created_at INTEGER NOT NULL )"
},
{
"type": "table",
"name": "machine_space_state",
"tbl_name": "machine_space_state",
"sql": "CREATE TABLE machine_space_state ( machine_id TEXT NOT NULL, space_id TEXT NOT NULL, type TEXT NOT NULL, data TEXT NOT NULL, observed_at INTEGER NOT NULL, PRIMARY KEY (machine_id, space_id, type), FOREIGN KEY (machine_id, space_id) REFERENCES space(machine_id, id) ON DELETE CASCADE )"
},
{
"type": "table",
"name": "organization",
Expand Down Expand Up @@ -138,12 +144,6 @@
"tbl_name": "space",
"sql": "CREATE INDEX space_project_idx ON space (machine_id, project_id)"
},
{
"type": "table",
"name": "space_state",
"tbl_name": "space_state",
"sql": "CREATE TABLE space_state ( machine_id TEXT NOT NULL, space_id TEXT NOT NULL, type TEXT NOT NULL, data TEXT NOT NULL, observed_at INTEGER NOT NULL, PRIMARY KEY (machine_id, space_id, type), FOREIGN KEY (machine_id, space_id) REFERENCES space(machine_id, id) ON DELETE CASCADE )"
},
{
"type": "table",
"name": "sqlite_sequence",
Expand Down
4 changes: 2 additions & 2 deletions apps/server/test/daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ afterAll(cleanup);

/*
* The desktop's Skills section without a read on demand: a real CodeWork server's skills daemon
* publishes, the app server mirrors it into `space_state` and tells the UI which space changed, and
* publishes, the app server mirrors it into `machine_space_state` and tells the UI which space changed, and
* `projects.skills` answers from the mirror.
*/
it("mirrors a space's skills from its daemon into the app and serves them from there", async () => {
Expand Down Expand Up @@ -59,7 +59,7 @@ it("mirrors a space's skills from its daemon into the app and serves them from t
const stored = () =>
query(
appHome,
"SELECT type, data FROM space_state WHERE machine_id = ? AND space_id = ? ORDER BY type",
"SELECT type, data FROM machine_space_state WHERE machine_id = ? AND space_id = ? ORDER BY type",
machineId,
spaceId,
).map((row) => ({ type: row.type, data: JSON.parse(row.data as string) as Record<string, unknown> }));
Expand Down