Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,19 @@ 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"
Comment on lines +107 to 113
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 BETTER_AUTH_SECRET not auto-generated

The three perl commands auto-populate ENCRYPTION_KEY, INTERNAL_API_SECRET, and API_ENCRYPTION_KEY, but BETTER_AUTH_SECRET (which carries the same "use openssl rand -hex 32" comment in .env.example) is left as the literal placeholder your_secret_key. A new contributor following the setup steps exactly will end up with an un-set auth secret and may not notice until they hit authentication errors at runtime.

Consider adding a fourth perl line for consistency:

perl -i -pe "s/your_secret_key/$(openssl rand -hex 32)/" apps/sim/.env

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhinavDhulipala we'd want to generate this too right?

```

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:
Expand Down
5 changes: 1 addition & 4 deletions apps/sim/.env.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/db/.env.example
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
23 changes: 23 additions & 0 deletions packages/db/scripts/migrate.ts
Original file line number Diff line number Diff line change
@@ -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()
Comment on lines +17 to +22
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 process.exit inside catch skips finally cleanup

process.exit(1) terminates the process synchronously, so the await client.end() in the finally block is never reached on failure. The OS will clean up the TCP connection when the process exits, so this is harmless in practice, but the finally guard becomes misleading. A cleaner pattern is to track the exit code and call process.exit once after finally runs:

Suggested change
} catch (error) {
console.error('ERROR: Migration failed.')
console.error(error instanceof Error ? error.message : error)
process.exit(1)
} finally {
await client.end()
} catch (error) {
console.error('ERROR: Migration failed.')
console.error(error instanceof Error ? error.message : error)
} finally {
await client.end()
}
process.exit(1)

Or use a variable:

let failed = false
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)
  failed = true
} finally {
  await client.end()
}
if (failed) process.exit(1)

}