Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Apr 4, 2024
1 parent 129bd3a commit c304599
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 106 deletions.
44 changes: 38 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
# ElectricSQL workflow
# DB Workflow

- Edit `prisma/schema.prisma`
- `pnpm migration:create` to create migrations using prisma cli and rename the files so it matches
`@databases/pg-migrations` syntax `{3digitsNumber}-{name}.sql`
- If new tables are created, add `ALTER TABLE table_name ENABLE ELECTRIC;` to your migration file
- `pnpm migration:up` to apply migrations to ElectricSQL proxy db
This app contains 2 databases on a single Postgres container, and a database proxy.

## Live data

#### ElectricSQL allows users to be notified when data changes.

To achieve this, every table containing "live" value must be created through the ElectricSQL proxy, with

```sql
ALTER TABLE table ENABLE ELECTRIC;
```

Electric Data is stored in the /cr-vif database of the Postgres container.

TS client can be generated with `electric-sql generate`, which uses
[prisma introspection](https://www.prisma.io/docs/orm/prisma-schema/introspection). It can be used in browser and/or
Node.

## Non-synchronized data

Non-synchronized data is stored in the /cr-vif-users database of the Postgres container.

## Migrations

### Electric

- Write migrations in `db/migrations/` and electrify tables using `ALTER TABLE table ENABLE ELECTRIC;`
- `pnpm migrate:electric` applys migrations to the proxy db and generate the TS client in
`./packages/frontend/src/generated`

### Users

- Edit `./packages/backend/src/db/schema.ts`
- `pnpm migrate:users` generates migrations files in `./backend/drizzle`
- Migrations are applied when the backend starts

![alt text](images/db-workflow.png)
Binary file added images/db-workflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"frontend": "pnpm --filter @cr-vif/frontend",
"backend": "pnpm --filter @cr-vif/backend",
"migration-users:create": "pnpm backend migration:create",
"migrate:users": "pnpm migration-users:create",
"migrate:electric": "pnpm migration:up && pnpm client:generate",
"migration-electric:up": "pnpm electric-sql with-config \"pnpm pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"client:generate": "pnpm frontend client:generate"
Expand Down
100 changes: 0 additions & 100 deletions packages/frontend/triplit/schema.ts

This file was deleted.

0 comments on commit c304599

Please sign in to comment.