generated from betagouv/template-nextjs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.