Skip to content

refactor(database): unify PostgreSQL/SQLite schemas via dialect shim#32255

Closed
jadsongmatos wants to merge 16 commits into
anomalyco:devfrom
jadsongmatos:clean-dialect-shim
Closed

refactor(database): unify PostgreSQL/SQLite schemas via dialect shim#32255
jadsongmatos wants to merge 16 commits into
anomalyco:devfrom
jadsongmatos:clean-dialect-shim

Conversation

@jadsongmatos

Copy link
Copy Markdown

Implements dialect shim pattern (from wgzesg/feat/configurable-database-backend) to unify PostgreSQL and SQLite schemas without duplicate .pg.ts files.

Changes

  • Add dialect shim (dialect.ts, dialect.sqlite.ts, dialect.pg.ts) with type mappings:

    • text({mode:'json'}) → jsonb()
    • integer() → bigint({mode:'number'})
    • integer({mode:'boolean'}) → boolean()
    • real() → doublePrecision()
  • Migrate 9 sql.ts files to import from shim, removing isPostgres() dispatch and .pg.ts duplicates:

    • credential, account, permission, event, share, project, data-migration, control-plane/workspace, session
  • Remove 10 .pg.ts files + schema.sql.ts, schema.pg.ts, path.pg.ts, pg-bootstrap.ts

  • Simplify tables.ts (no dispatch), migration.ts (no pg-bootstrap), path.ts (customType from shim), schema.ts (re-export Timestamps)

  • Fix project.test.ts: imports, fs.promises.realpath, ProjectV2.Directories test data, withRepo remote

Testing

  • Typecheck: clean
  • Tests: 25/25 pass in project.test.ts

Closes #14212

jadsongmatos and others added 16 commits March 31, 2026 15:33
Updated the explore agent's role and operational guidelines for file searching.
Add dual SQLite/PostgreSQL database backend. When OPENCODE_DATABASE_URL
is set to a postgres:// or postgresql:// URL, opencode uses PostgreSQL
instead of SQLite. No consumer code changes required.

- Add DatabaseDialect module to detect backend from env var
- Add effect-drizzle-pg package for Drizzle PG integration
- Add .pg.ts schema files for all tables with bigint timestamps
- Add conditional exports in sql.ts files (dialect-aware at runtime)
- Add pg-bootstrap.ts for fresh PG database initialization
- Add applyPg() migration path with bootstrap + incremental pgUp
- Add pg.layer.ts and #pg conditional import in package.json
- Add docker-compose.yml for local PG development
- Add project_directory and new permission tables to PG bootstrap
- Update database.ts to route based on dialect detection
Add @effect/sql-pg, pg, @libsql/client, and new @opencode-ai/effect-drizzle-pg package for PostgreSQL support. This enables using PostgreSQL as a database backend alongside existing SQLite.
…(wgzesg/feat/configurable-database-backend)

- Add dialect shim (dialect.ts, dialect.sqlite.ts, dialect.pg.ts) with type mappings:
  text({mode:'json'})→jsonb(), integer()→bigint({mode:'number'}), integer({mode:'boolean'})→boolean(), real()→doublePrecision()

- Migrate 9 sql.ts files to import from shim, removing isPostgres() dispatch and .pg.ts duplicates:
  credential, account, permission, event, share, project, data-migration, control-plane/workspace, session

- Remove 10 .pg.ts files + schema.sql.ts, schema.pg.ts, path.pg.ts, pg-bootstrap.ts

- Simplify tables.ts (no dispatch), migration.ts (no pg-bootstrap), path.ts (customType from shim), schema.ts (re-export Timestamps)

- Fix project.test.ts: imports, fs.promises.realpath, ProjectV2.Directories test data, withRepo remote

- database.ts retains DatabaseDialect.isPostgres() for runtime driver selection (correct)

Implements dialect shim pattern from wgzesg/opencode#feat/configurable-database-backend
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential duplicate found:

This PR has the exact same title as the current PR #32255. They are likely addressing the same refactoring work with the dialect shim pattern. You should verify whether one is a duplicate or supersedes the other.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 14, 2026
@github-actions github-actions Bot closed this Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Support more DBMS' for OpenCode state storage

1 participant