Configuring Plugin Databases
This guide covers a variety of production persistence use cases which are supported out of the box by Backstage. The database manager allows the developer to set the client and database connection details on a per plugin basis in addition to the base client and connection configuration. This means that you can use a SQLite 3 in-memory database for a specific plugin whilst using PostgreSQL for everything else and so on.
By default, Backstage uses automatically created databases for each plugin whose
names follow the backstage_plugin_<pluginId> pattern, e.g.
backstage_plugin_auth. You can configure a different database name prefix for
use cases where you have multiple deployments running on a shared database
instance or cluster.
With infrastructure defined as code or data (Terraform, AWS CloudFormation, etc.), you may have database credentials which lack permissions to create new databases or you do not have control over the database names. In these instances, you can set the database connection configuration on a per plugin basis.
Backstage supports all of these use cases with the DatabaseManager provided by
@backstage/backend-common. We will now cover how to use and configure
Backstage's databases.
Prerequisites
Dependencies
Please ensure the appropriate database drivers are installed in your backend
package. If you intend to use both PostgreSQL and SQLite, you can install
both of them.
Install pg if you need PostgreSQL:
yarn --cwd packages/backend add pg
Install SQLite 3 if you intend to set it as the client:
yarn --cwd packages/backend add better-sqlite3
From an operational perspective, you only need to install drivers for clients that are actively used.