chore: replace manual SQL migrations with node-pg-migrate
This commit is contained in:
@@ -35,18 +35,23 @@ npm run db:test:up
|
||||
|
||||
This starts Postgres on `localhost:55432`, database `redefined_test`.
|
||||
|
||||
### 2. Load the schema
|
||||
### 2. Run migrations
|
||||
|
||||
**PowerShell:**
|
||||
```powershell
|
||||
Get-Content init.sql | docker exec -i redefined-designs-test-db psql -U redefined_test -d redefined_test
|
||||
```
|
||||
**PowerShell / bash (same command, cross-platform via Node):**
|
||||
|
||||
**bash:**
|
||||
```bash
|
||||
docker exec -i redefined-designs-test-db psql -U redefined_test -d redefined_test < init.sql
|
||||
```
|
||||
cd backend
|
||||
$env:PGHOST="localhost"; $env:PGPORT="55432"; $env:PGUSER="redefined_test"; $env:PGPASSWORD="redefined_test"; $env:PGDATABASE="redefined_test"
|
||||
npm install
|
||||
npm run migrate:up
|
||||
|
||||
|
||||
This applies every migration in `backend/migrations/` in order, tracked in a `pgmigrations` table so re-running is always safe (already-applied migrations are skipped).
|
||||
|
||||
To add a new migration:
|
||||
|
||||
npm run migrate:create -- descriptive-name
|
||||
|
||||
This generates a timestamped file in `backend/migrations/` with `exports.up`/`exports.down` stubs — fill in `pgm.sql(...)` for both directions.
|
||||
### 3. Configure environment variables
|
||||
|
||||
**PowerShell:**
|
||||
|
||||
Reference in New Issue
Block a user