fix(setup): db migrate hard fail and correct ini env (#3946)

This commit is contained in:
abhinavDhulipala
2026-04-04 16:22:19 -07:00
committed by GitHub
parent f39b4c74dc
commit 7971a64e63
5 changed files with 32 additions and 7 deletions

View File

@@ -105,6 +105,11 @@ Or install manually via the [pgvector guide](https://github.com/pgvector/pgvecto
```bash
cp apps/sim/.env.example apps/sim/.env
# Create your secrets
perl -i -pe "s/your_encryption_key/$(openssl rand -hex 32)/" apps/sim/.env
perl -i -pe "s/your_internal_api_secret/$(openssl rand -hex 32)/" apps/sim/.env
perl -i -pe "s/your_api_encryption_key/$(openssl rand -hex 32)/" apps/sim/.env
# DB configs for migration
cp packages/db/.env.example packages/db/.env
# Edit both .env files to set DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio"
```
@@ -112,7 +117,7 @@ cp packages/db/.env.example packages/db/.env
4. Run migrations:
```bash
cd packages/db && bunx drizzle-kit migrate --config=./drizzle.config.ts
cd packages/db && bun run db:migrate
```
5. Start development servers:

View File

@@ -1,8 +1,5 @@
# Database (Required)
DATABASE_URL="postgresql://postgres:password@localhost:5432/postgres"
# PostgreSQL Port (Optional) - defaults to 5432 if not specified
# POSTGRES_PORT=5432
DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio"
# Authentication (Required unless DISABLE_AUTH=true)
BETTER_AUTH_SECRET=your_secret_key # Use `openssl rand -hex 32` to generate, or visit https://www.better-auth.com/docs/installation

View File

@@ -1,2 +1,2 @@
# Database URL (Required for migrations and database operations)
DATABASE_URL="postgresql://postgres:password@localhost:5432/simstudio"
DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio"

View File

@@ -20,7 +20,7 @@
},
"scripts": {
"db:push": "bunx drizzle-kit push --config=./drizzle.config.ts",
"db:migrate": "bun --env-file=.env --bun x drizzle-kit migrate --config=./drizzle.config.ts",
"db:migrate": "bun --env-file=.env run ./scripts/migrate.ts",
"db:studio": "bunx drizzle-kit studio --config=./drizzle.config.ts",
"type-check": "tsc --noEmit",
"lint": "biome check --write --unsafe .",

View File

@@ -0,0 +1,23 @@
import { drizzle } from 'drizzle-orm/postgres-js'
import { migrate } from 'drizzle-orm/postgres-js/migrator'
import postgres from 'postgres'
const url = process.env.DATABASE_URL
if (!url) {
console.error('ERROR: Missing DATABASE_URL environment variable.')
console.error('Ensure packages/db/.env is configured.')
process.exit(1)
}
const client = postgres(url, { max: 1, connect_timeout: 10 })
try {
await migrate(drizzle(client), { migrationsFolder: './migrations' })
console.log('Migrations applied successfully.')
} catch (error) {
console.error('ERROR: Migration failed.')
console.error(error instanceof Error ? error.message : error)
process.exit(1)
} finally {
await client.end()
}