Skip to content

Commit 19a41ab

Browse files
committed
sync
1 parent cd174d8 commit 19a41ab

6 files changed

Lines changed: 139 additions & 53 deletions

File tree

packages/opencode/migration/20260127173238_melted_union_jack/migration.sql renamed to packages/opencode/migration/20260127222353_familiar_lady_ursula/migration.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ CREATE TABLE `session` (
6262
--> statement-breakpoint
6363
CREATE TABLE `todo` (
6464
`session_id` text NOT NULL,
65-
`id` text NOT NULL,
6665
`content` text NOT NULL,
6766
`status` text NOT NULL,
6867
`priority` text NOT NULL,
6968
`position` integer NOT NULL,
7069
`time_created` integer NOT NULL,
7170
`time_updated` integer NOT NULL,
72-
CONSTRAINT `todo_pk` PRIMARY KEY(`session_id`, `id`),
71+
CONSTRAINT `todo_pk` PRIMARY KEY(`session_id`, `position`),
7372
CONSTRAINT `fk_todo_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE
7473
);
7574
--> statement-breakpoint
@@ -88,4 +87,4 @@ CREATE INDEX `part_message_idx` ON `part` (`message_id`);--> statement-breakpoin
8887
CREATE INDEX `part_session_idx` ON `part` (`session_id`);--> statement-breakpoint
8988
CREATE INDEX `session_project_idx` ON `session` (`project_id`);--> statement-breakpoint
9089
CREATE INDEX `session_parent_idx` ON `session` (`parent_id`);--> statement-breakpoint
91-
CREATE INDEX `todo_session_idx` ON `todo` (`session_id`);
90+
CREATE INDEX `todo_session_idx` ON `todo` (`session_id`);

packages/opencode/migration/20260127173238_melted_union_jack/snapshot.json renamed to packages/opencode/migration/20260127222353_familiar_lady_ursula/snapshot.json

Lines changed: 90 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": "7",
33
"dialect": "sqlite",
4-
"id": "0e365b40-39c4-447f-9729-9714d865d8ff",
4+
"id": "068758ed-a97a-46f6-8a59-6c639ae7c20c",
55
"prevIds": [
66
"00000000-0000-0000-0000-000000000000"
77
],
@@ -160,7 +160,17 @@
160160
"autoincrement": false,
161161
"default": null,
162162
"generated": null,
163-
"name": "created_at",
163+
"name": "time_created",
164+
"entityType": "columns",
165+
"table": "message"
166+
},
167+
{
168+
"type": "integer",
169+
"notNull": true,
170+
"autoincrement": false,
171+
"default": null,
172+
"generated": null,
173+
"name": "time_updated",
164174
"entityType": "columns",
165175
"table": "message"
166176
},
@@ -204,6 +214,26 @@
204214
"entityType": "columns",
205215
"table": "part"
206216
},
217+
{
218+
"type": "integer",
219+
"notNull": true,
220+
"autoincrement": false,
221+
"default": null,
222+
"generated": null,
223+
"name": "time_created",
224+
"entityType": "columns",
225+
"table": "part"
226+
},
227+
{
228+
"type": "integer",
229+
"notNull": true,
230+
"autoincrement": false,
231+
"default": null,
232+
"generated": null,
233+
"name": "time_updated",
234+
"entityType": "columns",
235+
"table": "part"
236+
},
207237
{
208238
"type": "text",
209239
"notNull": true,
@@ -224,6 +254,26 @@
224254
"entityType": "columns",
225255
"table": "permission"
226256
},
257+
{
258+
"type": "integer",
259+
"notNull": true,
260+
"autoincrement": false,
261+
"default": null,
262+
"generated": null,
263+
"name": "time_created",
264+
"entityType": "columns",
265+
"table": "permission"
266+
},
267+
{
268+
"type": "integer",
269+
"notNull": true,
270+
"autoincrement": false,
271+
"default": null,
272+
"generated": null,
273+
"name": "time_updated",
274+
"entityType": "columns",
275+
"table": "permission"
276+
},
227277
{
228278
"type": "text",
229279
"notNull": true,
@@ -360,37 +410,7 @@
360410
"autoincrement": false,
361411
"default": null,
362412
"generated": null,
363-
"name": "revert_message_id",
364-
"entityType": "columns",
365-
"table": "session"
366-
},
367-
{
368-
"type": "text",
369-
"notNull": false,
370-
"autoincrement": false,
371-
"default": null,
372-
"generated": null,
373-
"name": "revert_part_id",
374-
"entityType": "columns",
375-
"table": "session"
376-
},
377-
{
378-
"type": "text",
379-
"notNull": false,
380-
"autoincrement": false,
381-
"default": null,
382-
"generated": null,
383-
"name": "revert_snapshot",
384-
"entityType": "columns",
385-
"table": "session"
386-
},
387-
{
388-
"type": "text",
389-
"notNull": false,
390-
"autoincrement": false,
391-
"default": null,
392-
"generated": null,
393-
"name": "revert_diff",
413+
"name": "revert",
394414
"entityType": "columns",
395415
"table": "session"
396416
},
@@ -460,7 +480,7 @@
460480
"autoincrement": false,
461481
"default": null,
462482
"generated": null,
463-
"name": "id",
483+
"name": "content",
464484
"entityType": "columns",
465485
"table": "todo"
466486
},
@@ -470,7 +490,7 @@
470490
"autoincrement": false,
471491
"default": null,
472492
"generated": null,
473-
"name": "content",
493+
"name": "status",
474494
"entityType": "columns",
475495
"table": "todo"
476496
},
@@ -480,17 +500,17 @@
480500
"autoincrement": false,
481501
"default": null,
482502
"generated": null,
483-
"name": "status",
503+
"name": "priority",
484504
"entityType": "columns",
485505
"table": "todo"
486506
},
487507
{
488-
"type": "text",
508+
"type": "integer",
489509
"notNull": true,
490510
"autoincrement": false,
491511
"default": null,
492512
"generated": null,
493-
"name": "priority",
513+
"name": "position",
494514
"entityType": "columns",
495515
"table": "todo"
496516
},
@@ -500,7 +520,17 @@
500520
"autoincrement": false,
501521
"default": null,
502522
"generated": null,
503-
"name": "position",
523+
"name": "time_created",
524+
"entityType": "columns",
525+
"table": "todo"
526+
},
527+
{
528+
"type": "integer",
529+
"notNull": true,
530+
"autoincrement": false,
531+
"default": null,
532+
"generated": null,
533+
"name": "time_updated",
504534
"entityType": "columns",
505535
"table": "todo"
506536
},
@@ -544,6 +574,26 @@
544574
"entityType": "columns",
545575
"table": "session_share"
546576
},
577+
{
578+
"type": "integer",
579+
"notNull": true,
580+
"autoincrement": false,
581+
"default": null,
582+
"generated": null,
583+
"name": "time_created",
584+
"entityType": "columns",
585+
"table": "session_share"
586+
},
587+
{
588+
"type": "integer",
589+
"notNull": true,
590+
"autoincrement": false,
591+
"default": null,
592+
"generated": null,
593+
"name": "time_updated",
594+
"entityType": "columns",
595+
"table": "session_share"
596+
},
547597
{
548598
"columns": [
549599
"session_id"
@@ -637,7 +687,7 @@
637687
{
638688
"columns": [
639689
"session_id",
640-
"id"
690+
"position"
641691
],
642692
"nameExplicit": false,
643693
"name": "todo_pk",

packages/opencode/src/session/session.sql.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,16 @@ export const TodoTable = sqliteTable(
6767
session_id: text()
6868
.notNull()
6969
.references(() => SessionTable.id, { onDelete: "cascade" }),
70-
id: text().notNull(),
7170
content: text().notNull(),
7271
status: text().notNull(),
7372
priority: text().notNull(),
7473
position: integer().notNull(),
7574
...Timestamps,
7675
},
77-
(table) => [primaryKey({ columns: [table.session_id, table.id] }), index("todo_session_idx").on(table.session_id)],
76+
(table) => [
77+
primaryKey({ columns: [table.session_id, table.position] }),
78+
index("todo_session_idx").on(table.session_id),
79+
],
7880
)
7981

8082
export const PermissionTable = sqliteTable("permission", {

packages/opencode/src/session/todo.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export namespace Todo {
1010
content: z.string().describe("Brief description of the task"),
1111
status: z.string().describe("Current status of the task: pending, in_progress, completed, cancelled"),
1212
priority: z.string().describe("Priority level of the task: high, medium, low"),
13-
id: z.string().describe("Unique identifier for the todo item"),
1413
})
1514
.meta({ ref: "Todo" })
1615
export type Info = z.infer<typeof Info>
@@ -33,7 +32,6 @@ export namespace Todo {
3332
.values(
3433
input.todos.map((todo, position) => ({
3534
session_id: input.sessionID,
36-
id: todo.id,
3735
content: todo.content,
3836
status: todo.status,
3937
priority: todo.priority,
@@ -50,7 +48,6 @@ export namespace Todo {
5048
db.select().from(TodoTable).where(eq(TodoTable.session_id, sessionID)).orderBy(asc(TodoTable.position)).all(),
5149
)
5250
return rows.map((row) => ({
53-
id: row.id,
5451
content: row.content,
5552
status: row.status,
5653
priority: row.priority,

packages/opencode/src/storage/json-migration.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,15 @@ export namespace JsonMigration {
235235
}
236236
for (let position = 0; position < data.length; position++) {
237237
const todo = data[position]
238-
if (!todo?.id || !todo?.content || !todo?.status || !todo?.priority) continue
238+
if (!todo?.content || !todo?.status || !todo?.priority) continue
239239
values.push({
240240
session_id: sessionID,
241-
id: todo.id,
242241
content: todo.content,
243242
status: todo.status,
244243
priority: todo.priority,
245244
position,
245+
time_created: Date.now(),
246+
time_updated: Date.now(),
246247
})
247248
}
248249
}

packages/opencode/test/storage/json-migration.test.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,54 @@ describe("JSON to SQLite migration", () => {
282282
expect(stats?.todos).toBe(2)
283283

284284
const db = drizzle({ client: sqlite })
285-
const todos = db.select().from(TodoTable).all()
285+
const todos = db.select().from(TodoTable).orderBy(TodoTable.position).all()
286286
expect(todos.length).toBe(2)
287-
expect(todos[0].id).toBe("todo_1")
288287
expect(todos[0].content).toBe("First todo")
289288
expect(todos[0].status).toBe("pending")
290289
expect(todos[0].priority).toBe("high")
291290
expect(todos[0].position).toBe(0)
292-
expect(todos[1].id).toBe("todo_2")
291+
expect(todos[1].content).toBe("Second todo")
293292
expect(todos[1].position).toBe(1)
294293
})
295294

295+
test("todos are ordered by position", async () => {
296+
await Bun.write(
297+
path.join(storageDir, "project", "proj_test123abc.json"),
298+
JSON.stringify({
299+
id: "proj_test123abc",
300+
worktree: "/",
301+
time: { created: Date.now(), updated: Date.now() },
302+
sandboxes: [],
303+
}),
304+
)
305+
await Bun.write(
306+
path.join(storageDir, "session", "proj_test123abc", "ses_test456def.json"),
307+
JSON.stringify({ ...fixtures.session }),
308+
)
309+
310+
await Bun.write(
311+
path.join(storageDir, "todo", "ses_test456def.json"),
312+
JSON.stringify([
313+
{ content: "Third", status: "pending", priority: "low" },
314+
{ content: "First", status: "pending", priority: "high" },
315+
{ content: "Second", status: "in_progress", priority: "medium" },
316+
]),
317+
)
318+
319+
await JsonMigration.run(sqlite)
320+
321+
const db = drizzle({ client: sqlite })
322+
const todos = db.select().from(TodoTable).orderBy(TodoTable.position).all()
323+
324+
expect(todos.length).toBe(3)
325+
expect(todos[0].content).toBe("Third")
326+
expect(todos[0].position).toBe(0)
327+
expect(todos[1].content).toBe("First")
328+
expect(todos[1].position).toBe(1)
329+
expect(todos[2].content).toBe("Second")
330+
expect(todos[2].position).toBe(2)
331+
})
332+
296333
test("migrates permissions", async () => {
297334
// First create the project
298335
await Bun.write(

0 commit comments

Comments
 (0)