-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(setup): db migrate hard fail and correct init env #3946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" |
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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) |
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BETTER_AUTH_SECRETnot auto-generatedThe three
perlcommands auto-populateENCRYPTION_KEY,INTERNAL_API_SECRET, andAPI_ENCRYPTION_KEY, butBETTER_AUTH_SECRET(which carries the same "useopenssl rand -hex 32" comment in.env.example) is left as the literal placeholderyour_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
perlline for consistency:perl -i -pe "s/your_secret_key/$(openssl rand -hex 32)/" apps/sim/.envThere was a problem hiding this comment.
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?