Skip to content

Commit 3adb1d6

Browse files
committed
feat(db): add staging
1 parent 4d97a1f commit 3adb1d6

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ CONFIG_DISCORD_COMPONENTS_PAGE_SIZE='10' # The number of channels to display per
2929
# Postgres URLs
3030
POSTGRES_URL='postgresql://user:password@server:port/database'
3131
POSTGRES_DEV_URL='postgresql://user:password@server:port/database'
32+
POSTGRES_STAGING_URL='postgresql://user:password@server:port/database'

drizzle.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { defineConfig } from "drizzle-kit";
33
const databaseUrl =
44
process.env.NODE_ENV === "development"
55
? process.env.POSTGRES_DEV_URL
6-
: process.env.POSTGRES_URL;
6+
: process.env.NODE_ENV === "staging"
7+
? process.env.POSTGRES_STAGING_URL
8+
: process.env.POSTGRES_URL;
79

810
console.log("Using database URL:", databaseUrl);
911

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
"scripts": {
2525
"db:generate": "bun drizzle-kit generate",
2626
"db:push:dev": "cross-env NODE_ENV=development bun drizzle-kit push",
27+
"db:push:staging": "cross-env NODE_ENV=staging bun drizzle-kit push",
2728
"db:push:prod": "bun drizzle-kit push",
29+
"db:migrate:staging": "bun src/utils/migratedb.ts --staging",
30+
"db:migrate:prod": "bun src/utils/migratedb.ts",
2831
"dev": "concurrently --names \"WEB,API,BOT\" --prefix-colors \"blue,green,magenta\" \"cd web && bun dev\" \"cd api && cargo watch -x \\\"run -- --dev\\\"\" \"bun --watch . --dev\"",
2932
"dev:bot": "bun --watch . --dev",
3033
"test:jetstream": "bun --watch src/utils/bluesky/jetstream.ts",

src/config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// FILL IN THIS INFORMATION IN .ENV
22
export const runningInDevMode: boolean = process.argv.includes("--dev");
3+
4+
// Staging mode is for only testing the production database before breaking the actual production bot
5+
// Run `bun db:migrate:staging` to migrate the staging database and check for any mistakes before running `bun db:migrate:prod`
6+
// Do NOT use this mode for regular testing, use --dev for that
7+
export const runningInStagingMode: boolean = process.argv.includes("--staging");
8+
9+
if (runningInDevMode && runningInStagingMode) {
10+
throw new Error("Cannot run in both dev and staging mode!");
11+
}
12+
313
export interface Config {
414
youtubeInnertubeProxyUrl: string | null;
515
updateIntervalYouTube: number;
@@ -20,7 +30,9 @@ export const config: Config = {
2030
: 60_000,
2131
databaseUrl: runningInDevMode
2232
? process.env?.POSTGRES_DEV_URL
23-
: process.env?.POSTGRES_URL,
33+
: runningInStagingMode
34+
? process.env?.POSTGRES_STAGING_URL
35+
: process.env?.POSTGRES_URL,
2436
discordWaitForGuildCacheTime: process.env
2537
?.CONFIG_DISCORD_WAIT_FOR_GUILD_CACHE_TIME
2638
? parseInt(process.env?.CONFIG_DISCORD_WAIT_FOR_GUILD_CACHE_TIME) * 1000

0 commit comments

Comments
 (0)