mirror of
https://github.com/tiennm99/openai-status-bot.git
synced 2026-07-18 12:18:04 +00:00
Swap the Redis datastore for MongoDB via mongo-driver v2. New internal/mongostore mirrors the old redisstore type/constant names so consumers change only the import qualifier; document model collapses the multi-key subscriber/settings and per-event delivery sets into single-doc operations and a TTL-indexed delivery collection. Config now requires MONGODB_URI (Atlas) with MONGODB_DATABASE selecting dev vs prod on one cluster; REDIS_URL removed. Compose files run bot-only against Atlas. Default tests stay Docker-free (poller/bot use fakes, mongostore unit tests are pure-logic); a gated //go:build integration suite covers the real backend via testcontainers.
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
package mongostore
|
|
|
|
import "go.mongodb.org/mongo-driver/v2/mongo"
|
|
|
|
// Collection names. Each former Redis key becomes a MongoDB collection; the
|
|
// document model collapses the subscribers set + settings hash into one
|
|
// collection and replaces the per-event delivery sets with a single TTL-indexed
|
|
// collection.
|
|
const (
|
|
subscribersCollection = "subscribers"
|
|
componentStatusesCollection = "component_statuses"
|
|
pendingComponentEventsCollection = "pending_component_events"
|
|
incidentUpdateVersionsCollection = "incident_update_versions"
|
|
deliveryCollection = "delivery"
|
|
metaCollection = "meta"
|
|
)
|
|
|
|
// meta document IDs.
|
|
const (
|
|
metaInitializedID = "initialized"
|
|
metaTelegramOffsetID = "telegramOffset"
|
|
)
|
|
|
|
const (
|
|
SubscriptionTypeIncident = "incident"
|
|
SubscriptionTypeComponent = "component"
|
|
)
|
|
|
|
type Store struct {
|
|
db *mongo.Database
|
|
subscribers *mongo.Collection
|
|
componentStatuses *mongo.Collection
|
|
pendingComponentEvents *mongo.Collection
|
|
incidentUpdateVersions *mongo.Collection
|
|
delivery *mongo.Collection
|
|
meta *mongo.Collection
|
|
}
|
|
|
|
func New(client *mongo.Client, dbName string) *Store {
|
|
db := client.Database(dbName)
|
|
return &Store{
|
|
db: db,
|
|
subscribers: db.Collection(subscribersCollection),
|
|
componentStatuses: db.Collection(componentStatusesCollection),
|
|
pendingComponentEvents: db.Collection(pendingComponentEventsCollection),
|
|
incidentUpdateVersions: db.Collection(incidentUpdateVersionsCollection),
|
|
delivery: db.Collection(deliveryCollection),
|
|
meta: db.Collection(metaCollection),
|
|
}
|
|
}
|