From 259b2dfdbd27c9ee9071fcad7ba6e78f1ff89982 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Sat, 27 Jun 2026 16:26:37 +0700 Subject: [PATCH] fix(config): align mongodb database names --- .env.example | 2 +- README.md | 6 +++--- compose.dev.yaml | 4 ++-- compose.yaml | 2 +- docs/setup-guide.md | 6 +++--- docs/system-architecture.md | 2 +- internal/config/config.go | 2 +- internal/config/config_test.go | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.env.example b/.env.example index 7c08a23..b710ebc 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ TELEGRAM_BOT_TOKEN= MONGODB_URI=mongodb+srv://:@/ -MONGODB_DATABASE=openai_status_bot +MONGODB_DATABASE=openai-status-bot POLL_INTERVAL=1m HTTP_TIMEOUT=10s LOG_LEVEL=info diff --git a/README.md b/README.md index 16c46a0..a5c5b6b 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ a managed MongoDB Atlas cluster, so a reachable `MONGODB_URI` is required to start. The development and production setups share one cluster and differ only by database name (`MONGODB_DATABASE`). -Production runtime (default Compose file; uses the `MONGODB_DATABASE` from `.env`, default `openai_status_bot`): +Production runtime (default Compose file; uses the `MONGODB_DATABASE` from `.env`, default `openai-status-bot`): ```bash cp .env.example .env @@ -45,7 +45,7 @@ cp .env.example .env docker compose up -d --build ``` -Development runtime (targets the `development` database): +Development runtime (targets the `openai-status-bot-development` database): ```bash cp .env.example .env @@ -66,7 +66,7 @@ go run ./cmd/openai-status-bot |----------|---------|-------------| | `TELEGRAM_BOT_TOKEN` | required | Telegram bot token from BotFather | | `MONGODB_URI` | required | MongoDB connection string, e.g. an Atlas `mongodb+srv://user:pass@cluster/` URI | -| `MONGODB_DATABASE` | `openai_status_bot` | Database name; use a separate name (e.g. `development`) to split dev and prod on one cluster | +| `MONGODB_DATABASE` | `openai-status-bot` | Database name; use a separate name (e.g. `openai-status-bot-development`) to split dev and prod on one cluster | | `POLL_INTERVAL` | `1m` | Status check interval, valid `5s`-`1h` | | `HTTP_TIMEOUT` | `10s` | HTTP request timeout, valid `1s`-`5m` | | `LOG_LEVEL` | `info` | `debug`, `info`, `warn`/`warning`, or `error` | diff --git a/compose.dev.yaml b/compose.dev.yaml index 6126284..6e500ac 100644 --- a/compose.dev.yaml +++ b/compose.dev.yaml @@ -1,11 +1,11 @@ # Development runtime: bot only, connecting to the shared Atlas cluster. # There is no local datastore; set MONGODB_URI in .env. This file targets the -# development database (the MONGODB_DATABASE below overrides any .env value). +# openai-status-bot-development database (overrides any .env value). services: bot: build: . env_file: - .env environment: - MONGODB_DATABASE: development + MONGODB_DATABASE: openai-status-bot-development restart: unless-stopped diff --git a/compose.yaml b/compose.yaml index ba270c1..09665e7 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,6 +1,6 @@ # Default production runtime: bot only, connecting to the shared Atlas cluster via .env. # Uses the production database (MONGODB_DATABASE in .env, default -# openai_status_bot). There is no local datastore. +# openai-status-bot). There is no local datastore. services: bot: build: . diff --git a/docs/setup-guide.md b/docs/setup-guide.md index 97792f5..7436c18 100644 --- a/docs/setup-guide.md +++ b/docs/setup-guide.md @@ -12,7 +12,7 @@ cp .env.example .env # set TELEGRAM_BOT_TOKEN in .env # set MONGODB_URI to your MongoDB Atlas connection string -# docker compose sets MONGODB_DATABASE=development for local development +# docker compose sets MONGODB_DATABASE=openai-status-bot-development for local development docker compose -f compose.dev.yaml up --build ``` @@ -26,7 +26,7 @@ Use this for production deployment: cp .env.example .env # set TELEGRAM_BOT_TOKEN in .env # set MONGODB_URI to your MongoDB Atlas connection string -# MONGODB_DATABASE defaults to openai_status_bot (production) +# MONGODB_DATABASE defaults to openai-status-bot (production) docker compose up -d --build ``` @@ -37,7 +37,7 @@ cp .env.example .env # set TELEGRAM_BOT_TOKEN in .env # set MONGODB_URI to your MongoDB Atlas connection string # export TELEGRAM_BOT_TOKEN or source .env with your shell workflow -# MONGODB_DATABASE defaults to openai_status_bot +# MONGODB_DATABASE defaults to openai-status-bot go run ./cmd/openai-status-bot ``` diff --git a/docs/system-architecture.md b/docs/system-architecture.md index 5443d50..1aa88ef 100644 --- a/docs/system-architecture.md +++ b/docs/system-architecture.md @@ -41,7 +41,7 @@ The service uses Telegram `getUpdates` through `github.com/go-telegram/bot`, so `telegramOffset` stores the next update ID to resume from. Because `go-telegram/bot` stores the last seen update internally and sends `lastUpdateID + 1` to Telegram, startup passes `telegramOffset - 1` as the initial framework offset when a saved offset exists. The command handler saves `update.ID + 1` after every message update, including non-command messages. -MongoDB is configured with `MONGODB_URI` and `MONGODB_DATABASE` (default `openai_status_bot`). The OpenAI status source is fixed to `https://status.openai.com`. Docker Compose starts the bot connecting to a managed MongoDB Atlas cluster; there is no bundled local MongoDB service. +MongoDB is configured with `MONGODB_URI` and `MONGODB_DATABASE` (production default `openai-status-bot`; development Compose override `openai-status-bot-development`). The OpenAI status source is fixed to `https://status.openai.com`. Docker Compose starts the bot connecting to a managed MongoDB Atlas cluster; there is no bundled local MongoDB service. ## Failure Behavior diff --git a/internal/config/config.go b/internal/config/config.go index a394c45..e7491dc 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -22,7 +22,7 @@ const ( maxPollInterval = time.Hour minHTTPTimeout = time.Second maxHTTPTimeout = 5 * time.Minute - defaultMongoDatabase = "openai_status_bot" + defaultMongoDatabase = "openai-status-bot" ) func LoadFromEnv() (Config, error) { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 0b020bb..9053727 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -32,14 +32,14 @@ func TestLoadFromEnvDefaultsAndTrimming(t *testing.T) { func TestLoadFromEnvAcceptsCustomMongoDatabase(t *testing.T) { setMinimalEnv(t) - t.Setenv("MONGODB_DATABASE", " openai_status_bot_dev ") + t.Setenv("MONGODB_DATABASE", " openai-status-bot-development ") cfg, err := LoadFromEnv() if err != nil { t.Fatalf("LoadFromEnv returned error: %v", err) } - if cfg.MongoDatabase != "openai_status_bot_dev" { - t.Fatalf("MongoDatabase = %q, want openai_status_bot_dev", cfg.MongoDatabase) + if cfg.MongoDatabase != "openai-status-bot-development" { + t.Fatalf("MongoDatabase = %q, want openai-status-bot-development", cfg.MongoDatabase) } }