Skip to content

serverpod_database should expose a natural way to get a database connection from config #5046

Open

Description

@coderabbitai

Summary

The serverpod_database package should expose a first-class API for obtaining a database connection directly from a Serverpod config (e.g., loading config/<runMode>.yaml and config/passwords.yaml, then constructing a pool manager and database session).

Background

Currently, tools/serverpod_cli/lib/src/migrations/cli_migration_runner.dart manually replicates this logic — loading config files, constructing a DatabaseProvider, creating a pool manager, and wiring up a bespoke _CliDatabaseSession to work around the circular Session ↔ Database construction dependency — in order to apply pending migrations from outside the pod.

This logic is non-trivial and error-prone to duplicate. Exposing it as a proper API in serverpod_database would allow tooling (CLI, test utilities, etc.) to obtain a database connection in a clean, maintainable way without reimplementing internals.

References

Requested by @nielsenko.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: configuration

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions