refactor(database): unify PostgreSQL/SQLite schemas via dialect shim#32255
refactor(database): unify PostgreSQL/SQLite schemas via dialect shim#32255jadsongmatos wants to merge 16 commits into
Conversation
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
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
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. |
|
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. |
|
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. |
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:
Migrate 9 sql.ts files to import from shim, removing isPostgres() dispatch and .pg.ts duplicates:
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
Closes #14212