drizzle-team / drizzle-team/drizzle-orm

[FEATURE] Support local-first Postgres with ElectricSQL

Open
#1,951 5 comments 4 reactions 0 assignees View on GitHub
db/postgres driver/pglite drizzle/kit enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

ElectricSQL https://electric-sql.com/ is a growing open source reactive, realtime, local-first apps directly on Postgres.

Drizzle ORM's `migrate` (the one I'm using `'drizzle-orm/postgres-js/migrator'`) can't handle "electrifying" of tables in `.sql` files.

Steps:

1. I generate the migration file `0000_xxx.sql` with `yarn drizzle-kit generate:pg --config=./database/drizzle.config.ts`.
2. I add manually the electrifiying of tables https://electric-sql.com/docs/usage/data-modelling/migrations to `.sql` generated file.
```sql
...
-- After all table alterations are complete, enable Electric SQL
ALTER TABLE quotes ENABLE ELECTRIC;
ALTER TABLE authors ENABLE ELECTRIC;
ALTER TABLE collections ENABLE ELECTRIC;
```

3. Run Drizzle migration `yarn drizzle-kit generate:pg --config=./database/drizzle.config.ts`
4. Error. See terminal logs:

```shell
...
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "quotes" already exists, skipping',
file: 'parse_utilcmd.c',
line: '207',
routine: 'transformCreateStmt'
}
Migrations failed! PostgresError: syntax error at or near "ELECTRIC"
at ErrorResponse (file:///Users/guillem/.yarn/berry/cache/postgres-npm-3.4.3-eca46b47d6-10c0.zip/node_modules/postgres/src/connection.js:790:26)
at handle (file:///Users/guillem/.yarn/berry/cache/postgres-npm-3.4.3-eca46b47d6-10c0.zip/node_modules/postgres/src/connection.js:476:6)
at Socket.data (file:///Users/guillem/.yarn/berry/cache/postgres-npm-3.4.3-eca46b47d6-10c0.zip/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Socket.Readable.push (node:internal/streams/readable:390:5)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42601',
position: '309',
file: 'scan.l',
line: '1176',
routine: 'scanner_yyerror'
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.