Skip to content

Commit 7971a64

Browse files
fix(setup): db migrate hard fail and correct ini env (#3946)
1 parent f39b4c7 commit 7971a64

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,19 @@ Or install manually via the [pgvector guide](https://github.com/pgvector/pgvecto
105105

106106
```bash
107107
cp apps/sim/.env.example apps/sim/.env
108+
# Create your secrets
109+
perl -i -pe "s/your_encryption_key/$(openssl rand -hex 32)/" apps/sim/.env
110+
perl -i -pe "s/your_internal_api_secret/$(openssl rand -hex 32)/" apps/sim/.env
111+
perl -i -pe "s/your_api_encryption_key/$(openssl rand -hex 32)/" apps/sim/.env
112+
# DB configs for migration
108113
cp packages/db/.env.example packages/db/.env
109114
# Edit both .env files to set DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio"
110115
```
111116

112117
4. Run migrations:
113118

114119
```bash
115-
cd packages/db && bunx drizzle-kit migrate --config=./drizzle.config.ts
120+
cd packages/db && bun run db:migrate
116121
```
117122

118123
5. Start development servers:

apps/sim/.env.example

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Database (Required)
2-
DATABASE_URL="postgresql://postgres:password@localhost:5432/postgres"
3-
4-
# PostgreSQL Port (Optional) - defaults to 5432 if not specified
5-
# POSTGRES_PORT=5432
2+
DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio"
63

74
# Authentication (Required unless DISABLE_AUTH=true)
85
BETTER_AUTH_SECRET=your_secret_key # Use `openssl rand -hex 32` to generate, or visit https://www.better-auth.com/docs/installation

packages/db/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Database URL (Required for migrations and database operations)
2-
DATABASE_URL="postgresql://postgres:password@localhost:5432/simstudio"
2+
DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio"

packages/db/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"scripts": {
2222
"db:push": "bunx drizzle-kit push --config=./drizzle.config.ts",
23-
"db:migrate": "bun --env-file=.env --bun x drizzle-kit migrate --config=./drizzle.config.ts",
23+
"db:migrate": "bun --env-file=.env run ./scripts/migrate.ts",
2424
"db:studio": "bunx drizzle-kit studio --config=./drizzle.config.ts",
2525
"type-check": "tsc --noEmit",
2626
"lint": "biome check --write --unsafe .",

packages/db/scripts/migrate.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { drizzle } from 'drizzle-orm/postgres-js'
2+
import { migrate } from 'drizzle-orm/postgres-js/migrator'
3+
import postgres from 'postgres'
4+
5+
const url = process.env.DATABASE_URL
6+
if (!url) {
7+
console.error('ERROR: Missing DATABASE_URL environment variable.')
8+
console.error('Ensure packages/db/.env is configured.')
9+
process.exit(1)
10+
}
11+
12+
const client = postgres(url, { max: 1, connect_timeout: 10 })
13+
14+
try {
15+
await migrate(drizzle(client), { migrationsFolder: './migrations' })
16+
console.log('Migrations applied successfully.')
17+
} catch (error) {
18+
console.error('ERROR: Migration failed.')
19+
console.error(error instanceof Error ? error.message : error)
20+
process.exit(1)
21+
} finally {
22+
await client.end()
23+
}

0 commit comments

Comments
 (0)