Skip to content

Commit 5d9226a

Browse files
Apply PR #10597: sqlite again
2 parents e85ab17 + 2dae94e commit 5d9226a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3618
-873
lines changed

.opencode/command/commit.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ wip:
1616

1717
For anything in the packages/web use the docs: prefix.
1818

19-
For anything in the packages/app use the ignore: prefix.
20-
2119
prefer to explain WHY something was done from an end user perspective instead of
2220
WHAT was done.
2321

2422
do not do generic messages like "improved agent experience" be very specific
2523
about what user facing changes were made
2624

27-
if there are changes do a git pull --rebase
2825
if there are conflicts DO NOT FIX THEM. notify me and I will fix them
2926

3027
## GIT DIFF

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ const table = sqliteTable("session", {
110110

111111
- Avoid mocks as much as possible
112112
- Test actual implementation, do not duplicate logic into tests
113+
- Tests cannot run from repo root (guard: `do-not-run-tests-from-root`); run from package dirs like `packages/opencode`.

bun.lock

Lines changed: 204 additions & 195 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
"@tailwindcss/vite": "4.1.11",
4141
"diff": "8.0.2",
4242
"dompurify": "3.3.1",
43+
"drizzle-kit": "1.0.0-beta.12-a5629fb",
44+
"drizzle-orm": "1.0.0-beta.12-a5629fb",
4345
"ai": "5.0.124",
4446
"hono": "4.10.7",
4547
"hono-openapi": "1.1.2",

packages/app/src/context/global-sync.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,23 @@ function createGlobalSync() {
841841
)
842842
break
843843
}
844+
case "message.part.delta": {
845+
const parts = store.part[event.properties.messageID]
846+
if (!parts) break
847+
const result = Binary.search(parts, event.properties.partID, (p) => p.id)
848+
if (!result.found) break
849+
setStore(
850+
"part",
851+
event.properties.messageID,
852+
produce((draft) => {
853+
const part = draft[result.index]
854+
const field = event.properties.field as keyof typeof part
855+
const existing = part[field] as string | undefined
856+
;(part[field] as string) = (existing ?? "") + event.properties.delta
857+
}),
858+
)
859+
break
860+
}
844861
case "message.part.removed": {
845862
const messageID = event.properties.messageID
846863
const parts = store.part[messageID]

packages/console/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@opencode-ai/console-resource": "workspace:*",
1313
"@planetscale/database": "1.19.0",
1414
"aws4fetch": "1.0.20",
15-
"drizzle-orm": "0.41.0",
15+
"drizzle-orm": "catalog:",
1616
"postgres": "3.4.7",
1717
"stripe": "18.0.0",
1818
"ulid": "catalog:",
@@ -43,7 +43,7 @@
4343
"@tsconfig/node22": "22.0.2",
4444
"@types/bun": "1.3.0",
4545
"@types/node": "catalog:",
46-
"drizzle-kit": "0.30.5",
46+
"drizzle-kit": "catalog:",
4747
"mysql2": "3.14.4",
4848
"typescript": "catalog:",
4949
"@typescript/native-preview": "catalog:"

packages/console/core/src/drizzle/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export * from "drizzle-orm"
44
import { Client } from "@planetscale/database"
55

66
import { MySqlTransaction, type MySqlTransactionConfig } from "drizzle-orm/mysql-core"
7-
import type { ExtractTablesWithRelations } from "drizzle-orm"
87
import type { PlanetScalePreparedQueryHKT, PlanetscaleQueryResultHKT } from "drizzle-orm/planetscale-serverless"
98
import { Context } from "../context"
109
import { memo } from "../util/memo"
@@ -14,7 +13,7 @@ export namespace Database {
1413
PlanetscaleQueryResultHKT,
1514
PlanetScalePreparedQueryHKT,
1615
Record<string, never>,
17-
ExtractTablesWithRelations<Record<string, never>>
16+
any
1817
>
1918

2019
const client = memo(() => {
@@ -23,7 +22,7 @@ export namespace Database {
2322
username: Resource.Database.username,
2423
password: Resource.Database.password,
2524
})
26-
const db = drizzle(result, {})
25+
const db = drizzle({ client: result })
2726
return db
2827
})
2928

packages/opencode/AGENTS.md

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
1-
# opencode agent guidelines
1+
# opencode database guide
22

3-
## Build/Test Commands
3+
## Database
44

5-
- **Install**: `bun install`
6-
- **Run**: `bun run --conditions=browser ./src/index.ts`
7-
- **Typecheck**: `bun run typecheck` (npm run typecheck)
8-
- **Test**: `bun test` (runs all tests)
9-
- **Single test**: `bun test test/tool/tool.test.ts` (specific test file)
10-
11-
## Code Style
12-
13-
- **Runtime**: Bun with TypeScript ESM modules
14-
- **Imports**: Use relative imports for local modules, named imports preferred
15-
- **Types**: Zod schemas for validation, TypeScript interfaces for structure
16-
- **Naming**: camelCase for variables/functions, PascalCase for classes/namespaces
17-
- **Error handling**: Use Result patterns, avoid throwing exceptions in tools
18-
- **File structure**: Namespace-based organization (e.g., `Tool.define()`, `Session.create()`)
19-
20-
## Architecture
21-
22-
- **Tools**: Implement `Tool.Info` interface with `execute()` method
23-
- **Context**: Pass `sessionID` in tool context, use `App.provide()` for DI
24-
- **Validation**: All inputs validated with Zod schemas
25-
- **Logging**: Use `Log.create({ service: "name" })` pattern
26-
- **Storage**: Use `Storage` namespace for persistence
27-
- **API Client**: The TypeScript TUI (built with SolidJS + OpenTUI) communicates with the OpenCode server using `@opencode-ai/sdk`. When adding/modifying server endpoints in `packages/opencode/src/server/server.ts`, run `./script/generate.ts` to regenerate the SDK and related files.
5+
- **Schema**: Drizzle schema lives in `src/**/*.sql.ts`.
6+
- **Naming**: tables and columns use snake*case; join columns are `<entity>_id`; indexes are `<table>*<column>\_idx`.
7+
- **Migrations**: generated by Drizzle Kit using `drizzle.config.ts` (schema: `./src/**/*.sql.ts`, output: `./migration`).
8+
- **Command**: `bun run db generate --name <slug>`.
9+
- **Output**: creates `migration/<timestamp>_<slug>/migration.sql` and `snapshot.json`.
10+
- **Tests**: migration tests should read the per-folder layout (no `_journal.json`).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "drizzle-kit"
2+
3+
export default defineConfig({
4+
dialect: "sqlite",
5+
schema: "./src/**/*.sql.ts",
6+
out: "./migration",
7+
dbCredentials: {
8+
url: "/home/thdxr/.local/share/opencode/opencode.db",
9+
},
10+
})
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
CREATE TABLE `project` (
2+
`id` text PRIMARY KEY,
3+
`worktree` text NOT NULL,
4+
`vcs` text,
5+
`name` text,
6+
`icon_url` text,
7+
`icon_color` text,
8+
`time_created` integer NOT NULL,
9+
`time_updated` integer NOT NULL,
10+
`time_initialized` integer,
11+
`sandboxes` text NOT NULL
12+
);
13+
--> statement-breakpoint
14+
CREATE TABLE `message` (
15+
`id` text PRIMARY KEY,
16+
`session_id` text NOT NULL,
17+
`time_created` integer NOT NULL,
18+
`time_updated` integer NOT NULL,
19+
`data` text NOT NULL,
20+
CONSTRAINT `fk_message_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE
21+
);
22+
--> statement-breakpoint
23+
CREATE TABLE `part` (
24+
`id` text PRIMARY KEY,
25+
`message_id` text NOT NULL,
26+
`session_id` text NOT NULL,
27+
`time_created` integer NOT NULL,
28+
`time_updated` integer NOT NULL,
29+
`data` text NOT NULL,
30+
CONSTRAINT `fk_part_message_id_message_id_fk` FOREIGN KEY (`message_id`) REFERENCES `message`(`id`) ON DELETE CASCADE
31+
);
32+
--> statement-breakpoint
33+
CREATE TABLE `permission` (
34+
`project_id` text PRIMARY KEY,
35+
`time_created` integer NOT NULL,
36+
`time_updated` integer NOT NULL,
37+
`data` text NOT NULL,
38+
CONSTRAINT `fk_permission_project_id_project_id_fk` FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON DELETE CASCADE
39+
);
40+
--> statement-breakpoint
41+
CREATE TABLE `session` (
42+
`id` text PRIMARY KEY,
43+
`project_id` text NOT NULL,
44+
`parent_id` text,
45+
`slug` text NOT NULL,
46+
`directory` text NOT NULL,
47+
`title` text NOT NULL,
48+
`version` text NOT NULL,
49+
`share_url` text,
50+
`summary_additions` integer,
51+
`summary_deletions` integer,
52+
`summary_files` integer,
53+
`summary_diffs` text,
54+
`revert` text,
55+
`permission` text,
56+
`time_created` integer NOT NULL,
57+
`time_updated` integer NOT NULL,
58+
`time_compacting` integer,
59+
`time_archived` integer,
60+
CONSTRAINT `fk_session_project_id_project_id_fk` FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON DELETE CASCADE
61+
);
62+
--> statement-breakpoint
63+
CREATE TABLE `todo` (
64+
`session_id` text NOT NULL,
65+
`content` text NOT NULL,
66+
`status` text NOT NULL,
67+
`priority` text NOT NULL,
68+
`position` integer NOT NULL,
69+
`time_created` integer NOT NULL,
70+
`time_updated` integer NOT NULL,
71+
CONSTRAINT `todo_pk` PRIMARY KEY(`session_id`, `position`),
72+
CONSTRAINT `fk_todo_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE
73+
);
74+
--> statement-breakpoint
75+
CREATE TABLE `session_share` (
76+
`session_id` text PRIMARY KEY,
77+
`id` text NOT NULL,
78+
`secret` text NOT NULL,
79+
`url` text NOT NULL,
80+
`time_created` integer NOT NULL,
81+
`time_updated` integer NOT NULL,
82+
CONSTRAINT `fk_session_share_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE
83+
);
84+
--> statement-breakpoint
85+
CREATE INDEX `message_session_idx` ON `message` (`session_id`);--> statement-breakpoint
86+
CREATE INDEX `part_message_idx` ON `part` (`message_id`);--> statement-breakpoint
87+
CREATE INDEX `part_session_idx` ON `part` (`session_id`);--> statement-breakpoint
88+
CREATE INDEX `session_project_idx` ON `session` (`project_id`);--> statement-breakpoint
89+
CREATE INDEX `session_parent_idx` ON `session` (`parent_id`);--> statement-breakpoint
90+
CREATE INDEX `todo_session_idx` ON `todo` (`session_id`);

0 commit comments

Comments
 (0)