Skip to content

refactor(api): remove MongoDB store, keep Postgres as sole implementation#6429

Merged
gustavosbarreto merged 2 commits into
masterfrom
feat/remove-mongodb-store
Jun 5, 2026
Merged

refactor(api): remove MongoDB store, keep Postgres as sole implementation#6429
gustavosbarreto merged 2 commits into
masterfrom
feat/remove-mongodb-store

Conversation

@otavio
Copy link
Copy Markdown
Member

@otavio otavio commented Jun 5, 2026

What

Removes the entire MongoDB store implementation and the one-time Mongo→Postgres data-migration tool, leaving the store.Store interface in place with PostgreSQL as the only implementation.

⚠️ Merge in lockstep with the cloud PR

This must merge together with the companion PR in shellhub-io/cloud (branch feat/remove-mongodb-store). Cloud builds against this repo via replace => ../shellhub and imports the now-deleted api/store/mongo and api/store/migrate packages. Merging this alone breaks cloud main/CI until the cloud PR lands. Coordinate the merges.

Why

The Mongo→Postgres migration is finalized; the MongoDB backend and its migration code are dead weight. The interface abstraction is intentionally preserved so a future backend remains possible.

Changes

  • store: deleted api/store/mongo/ (impl + 119 migrations), api/store/migrate/ (incl. RegisterMigrationExtension), storetest/mongoprovider/, and api/pkg/dbtest/. Kept the store.Store interface, mocks, the generic storetest harness, RegisterStoreWrapper, and pg/internal legacyMongoFieldMapping.
  • wiring: api server and cli construct the pg store unconditionally. Dropped the DATABASE switch, the migrate mode (and its unauthenticated GET /api/migration/status listener), and MONGO_URI. The cli keeps its existing pg options and does not run migrations.
  • errors: added store.ErrInternal (unique error code). pg.fromSQLError wraps unmapped errors with it so the echo handler keeps reporting unknown DB errors to Sentry as 500s; context.Canceled/DeadlineExceeded pass through unwrapped to avoid alert noise. Removed the dead mongo.ErrUserNotFound branch in removeMember — absent members are already caught by the FindMember precheck.
  • deps: go mod tidy dropped mongo-driver, mongotest, mongo-lock, mongo-migrate, and the mongodb testcontainers module; modules/postgres retained.
  • infra/ci: removed docker-compose.mongo*.yml, the mongo leg of bin/docker-compose, MONGO_URI from the enterprise compose, and the database: mongo qa matrix entry (postgres leg kept).

Testing

  • go build ./... and go vet ./... clean in api/ and cli/.
  • New unit tests cover: fromSQLError wrapping vs. context-error passthrough; the handler reporting ErrInternal (and not reporting ErrNoDocuments/context.Canceled); and the removeMember precheck path.
  • The pg storetest suite (proof the pg store still satisfies the full interface) passes in the dev stack.

Follow-up

The docs repo upgrade guide (self-hosted/upgrading.md) still references the removed GET /api/migration/status endpoint — separate docs PR.

…tion

The Mongo->Postgres migration is finalized, so the MongoDB store and the
one-time data-migration tool are removed. The store.Store interface is
preserved with PostgreSQL as the only implementation.

Store construction is now pg-only: the DATABASE switch, the "migrate" mode
(and its unauthenticated /api/migration/status endpoint), and MONGO_URI are
gone from the api server and cli.

Unknown database errors are now wrapped in the new store.ErrInternal so the
echo error handler keeps reporting them to Sentry as 500s; context
cancellation/deadline errors pass through unwrapped to avoid noise. The dead
mongo.ErrUserNotFound branch in removeMember is dropped (the FindMember
precheck already handles absent members).
@otavio otavio requested review from a team as code owners June 5, 2026 01:23
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

Claude finished @otavio's task in 6m 23s —— View job


Code Review Complete

Reviewed 23 modified/added files across code quality, security, testing, Go patterns, and architecture — no issues found. The code looks good as-is.

Review highlights:

  • Error handling: fromSQLError correctly wraps unmapped errors with store.ErrInternal while passing through context.Canceled/DeadlineExceeded. The error handler's ErrInternal → Sentry + 500 path works correctly with errors.Join.
  • Dead code removal: The mongo.ErrUserNotFound branch in removeMember was indeed dead — the FindMember precheck on line 155 already catches absent members before removeMember is called.
  • Cross-repo compatibility: Cloud's feat/remove-mongodb-store branch has no remaining imports of deleted packages (api/store/mongo, api/store/migrate, api/pkg/dbtest). store.Store interface is preserved. No breaking changes detected.
  • Test coverage: New tests cover fromSQLError wrapping, context-error passthrough, the error handler's Sentry reporting, removeMember error propagation, and cleanup guard tests that assert mongo dirs/deps are gone.
  • Security: Removing the unauthenticated GET /api/migration/status endpoint reduces attack surface. No new vulnerabilities introduced.

To request another review round, comment /review.

gofumpt formatting in utils_test.go and an nlreturn blank line before
break in cleanup_test.go.
@gustavosbarreto gustavosbarreto merged commit a53963c into master Jun 5, 2026
11 checks passed
@gustavosbarreto gustavosbarreto deleted the feat/remove-mongodb-store branch June 5, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants