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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ SLACK_BOT_TOKEN=xoxb-
SLACK_APP_TOKEN=xapp-
GITHUB_TOKEN=github_pat_
DATABASE_URL=postgres://root:password@localhost:5432/app
# DATABASE_POOL_MAX=10
1 change: 1 addition & 0 deletions installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ DATABASE_URL=postgres://user:password@localhost/releases_db
# Optional
# POLL_CRON=0 * * * * # How often to check releases (default: every hour)
# DIGEST_CRON=30 7 * * * # When to send the periodic digest in UTC (default: 07:30 UTC)
# DATABASE_POOL_MAX=10 # Max connections in the DB connection pool (default: 10)
```

All tables are created in the `main` PostgreSQL schema. To use a different schema, change the hardcoded value in `src/db/schema.ts` and `drizzle.config.ts`, then regenerate and re-apply migrations.
Expand Down
12 changes: 7 additions & 5 deletions src/db/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { drizzle } from 'drizzle-orm/bun-sql'
import { positiveInt, requiredString } from '@utils/env'

if (!process.env.DATABASE_URL) {
throw new Error('DATABASE_URL is required')
}

export const db = drizzle(process.env.DATABASE_URL)
export const db = drizzle({
connection: {
url: requiredString('DATABASE_URL'),
max: positiveInt('DATABASE_POOL_MAX', 10),
},
})
1 change: 1 addition & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare module 'bun' {

// Database
DATABASE_URL: string
DATABASE_POOL_MAX?: string
// Jobs
POLL_CRON?: string
DIGEST_CRON?: string
Expand Down
5 changes: 3 additions & 2 deletions src/slack/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { App } from '@slack/bolt'
import { requiredString } from '@utils/env.ts'

export const app = new App({
token: process.env.SLACK_BOT_TOKEN,
appToken: process.env.SLACK_APP_TOKEN,
token: requiredString('SLACK_BOT_TOKEN'),
appToken: requiredString('SLACK_APP_TOKEN'),
socketMode: true,
})
24 changes: 24 additions & 0 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
type EnvVarName = keyof typeof process.env

export function requiredString(name: EnvVarName): string {
const value = process.env[name]
if (!value) {
throw new Error(`${name} is required`)
}

return value
}

export function positiveInt(name: EnvVarName, defaultValue: number): number {
const raw = process.env[name]
if (!raw) {
return defaultValue
}

const value = Number(raw)
if (!Number.isInteger(value) || value < 1) {
throw new Error(`${name} must be a positive integer`)
}

return value
}
11 changes: 6 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"noEmit": true,
"skipLibCheck": true,
"paths": {
"@db/*": ["./src/db/*"],
"@forges/*": ["./src/forges/*"],
"@bot/*": ["./src/slack/*"],
"@jobs/*": ["./src/jobs/*"],
"@classify/*": ["./src/classify/*"]
"@db/*": ["./src/db/*"],
"@forges/*": ["./src/forges/*"],
"@bot/*": ["./src/slack/*"],
"@jobs/*": ["./src/jobs/*"],
"@classify/*": ["./src/classify/*"],
"@utils/*": ["./src/utils/*"]
}
}
}