rogasper commited on
Commit
d0190d5
Β·
1 Parent(s): 65bc265

refactor: update database migration instructions in COOLIFY.md for clarity and remove post-deployment command. Adjust server.nixpacks.toml to ensure migrations run before starting the server.

Browse files
Files changed (2) hide show
  1. deploy/COOLIFY.md +20 -14
  2. deploy/server.nixpacks.toml +1 -1
deploy/COOLIFY.md CHANGED
@@ -122,29 +122,35 @@ PLATFORM_AI_MODEL=
122
  FREE_CREDITS_ENABLED=false
123
  ```
124
 
125
- ### Post-deployment command (migrations)
126
 
127
- In the server application: **Configuration β†’ Advanced β†’ Post-deployment Command**:
128
 
129
- ```bash
130
- bun run db:migrate
131
- ```
132
 
133
- Run on first deploy and after schema changes. Alternative for local-style sync: `bun run db:push`.
 
 
134
 
135
- **`DATABASE_URL` must be set in Coolify Environment Variables** before deploy. The container does not have `apps/server/.env` (it is gitignored). Drizzle reads `DATABASE_URL` from `process.env` in production.
136
 
137
- To get the connection string from a Coolify PostgreSQL service:
138
-
139
- 1. Open your PostgreSQL resource β†’ **Configuration** or **Connect**
140
- 2. Copy the **internal** connection URL (hostname is the Docker service name, not `localhost`)
141
- 3. Paste into the server app env:
142
 
143
  ```env
144
  DATABASE_URL=postgresql://postgres:YOUR_PASSWORD@YOUR_POSTGRES_HOST:5432/labas
145
  ```
146
 
147
- If migrate fails with `url: ''`, `DATABASE_URL` is missing or empty in the server app's environment β€” fix that and redeploy.
 
 
 
 
 
 
 
 
148
 
149
  Optional seed (run once via **Terminal** on the server app):
150
 
@@ -207,7 +213,7 @@ Rebuild the web app whenever the API URL changes.
207
 
208
  1. [ ] Deploy PostgreSQL and Redis; confirm both are healthy.
209
  2. [ ] Create server app, set all runtime env vars.
210
- 3. [ ] Set **Post-deployment Command** to `bun run db:migrate` (after `DATABASE_URL` is set).
211
  4. [ ] Deploy server; confirm `https://api.example.com/` returns `OK`.
212
  5. [ ] Create web app, set `VITE_SERVER_URL` as **buildtime** env.
213
  6. [ ] Deploy web; confirm app loads and API calls reach the server.
 
122
  FREE_CREDITS_ENABLED=false
123
  ```
124
 
125
+ ### Database migrations
126
 
127
+ Migrations run automatically on container start (see [`deploy/server.nixpacks.toml`](./server.nixpacks.toml)). **Remove any Post-deployment Command** for `db:migrate` β€” it often runs without runtime env vars in Coolify.
128
 
129
+ **`DATABASE_URL` must be set on the server application** (not on the PostgreSQL resource). The container does not have `apps/server/.env` (gitignored).
 
 
130
 
131
+ 1. Open **server application** β†’ **Environment Variables**
132
+ 2. Add `DATABASE_URL` with **Available at Runtime** enabled (default)
133
+ 3. Do **not** set it as Build-only
134
 
135
+ To get the connection string:
136
 
137
+ 1. Open your **PostgreSQL** resource β†’ **Connect** / **Configuration**
138
+ 2. Copy the **internal** URL (Docker hostname, not `localhost`)
139
+ 3. Paste into the **server app** env:
 
 
140
 
141
  ```env
142
  DATABASE_URL=postgresql://postgres:YOUR_PASSWORD@YOUR_POSTGRES_HOST:5432/labas
143
  ```
144
 
145
+ Verify in the server app **Terminal**:
146
+
147
+ ```bash
148
+ echo $DATABASE_URL
149
+ ```
150
+
151
+ If empty, the variable is missing or not marked as runtime β€” fix and redeploy.
152
+
153
+ Alternative for local-style sync (not recommended in production): `bun run db:push`.
154
 
155
  Optional seed (run once via **Terminal** on the server app):
156
 
 
213
 
214
  1. [ ] Deploy PostgreSQL and Redis; confirm both are healthy.
215
  2. [ ] Create server app, set all runtime env vars.
216
+ 3. [ ] Set `DATABASE_URL` on **server app** env (Runtime). Remove Post-deployment migrate command.
217
  4. [ ] Deploy server; confirm `https://api.example.com/` returns `OK`.
218
  5. [ ] Create web app, set `VITE_SERVER_URL` as **buildtime** env.
219
  6. [ ] Deploy web; confirm app loads and API calls reach the server.
deploy/server.nixpacks.toml CHANGED
@@ -11,4 +11,4 @@ cmds = ["bun install --frozen-lockfile"]
11
  cmds = ["bunx turbo build -F server"]
12
 
13
  [start]
14
- cmd = "bun run --cwd apps/server start"
 
11
  cmds = ["bunx turbo build -F server"]
12
 
13
  [start]
14
+ cmd = "bun run db:migrate && bun run --cwd apps/server start"