diff --git a/README.md b/README.md index 114d5ffc207..0229f5f2bd1 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,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" ``` @@ -111,7 +116,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: diff --git a/apps/sim/.env.example b/apps/sim/.env.example index fe9514e358e..6490656a146 100644 --- a/apps/sim/.env.example +++ b/apps/sim/.env.example @@ -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 diff --git a/packages/db/.env.example b/packages/db/.env.example index 93591dc12da..bc06b7099c5 100644 --- a/packages/db/.env.example +++ b/packages/db/.env.example @@ -1,2 +1,2 @@ # Database URL (Required for migrations and database operations) -DATABASE_URL="postgresql://postgres:password@localhost:5432/simstudio" \ No newline at end of file +DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio" \ No newline at end of file diff --git a/packages/db/package.json b/packages/db/package.json index ed785572070..92b8abd9cc0 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -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 .", diff --git a/packages/db/scripts/migrate.ts b/packages/db/scripts/migrate.ts new file mode 100644 index 00000000000..1ef938bc5a9 --- /dev/null +++ b/packages/db/scripts/migrate.ts @@ -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() +}