Interface DatabaseSpec
- All Known Implementing Classes:
BagistoApplicationSpec, ConcreteCmsApplicationSpec, DolphinApplicationSpec, DrupalApplicationSpec, FlarumApplicationSpec, GitLabApplicationSpec, GrafanaApplicationSpec, HarborApplicationSpec, JoomlaApplicationSpec, MagentoApplicationSpec, MattermostApplicationSpec, MattermostTeamApplicationSpec, MediaWikiApplicationSpec, MetabaseApplicationSpec, MoodleApplicationSpec, MyBBApplicationSpec, OctoberCmsApplicationSpec, OpenCartApplicationSpec, PhpBBApplicationSpec, PrestaShopApplicationSpec, SuiteCrmApplicationSpec, SupersetApplicationSpec, SyliusApplicationSpec, Typo3ApplicationSpec, WooCommerceApplicationSpec, WordPressApplicationSpec
public interface DatabaseSpec
Database specification interface for applications requiring external databases.
Applications implementing this interface can request managed RDS databases instead of using embedded file-based databases.
Supported Engines:
- PostgreSQL (postgres)
- MySQL (mysql)
- MariaDB (mariadb)
- Aurora PostgreSQL (aurora-postgresql)
- Aurora MySQL (aurora-mysql)
Example Usage:
public class MetabaseApplicationSpec implements ApplicationSpec, DatabaseSpec {
@Override
public DatabaseRequirement databaseRequirement() {
return DatabaseRequirement.optional("postgres", "15");
}
@Override
public Map<String, String> containerEnvironmentVariables(
String fqdn, boolean sslEnabled, String authMode, DatabaseConnection dbConn) {
if (dbConn != null) {
return Map.of(
"MB_DB_TYPE", "postgres",
"MB_DB_HOST", dbConn.endpoint(),
"MB_DB_PORT", String.valueOf(dbConn.port()),
"MB_DB_DBNAME", dbConn.databaseName(),
"MB_DB_USER", dbConn.username(),
"MB_DB_PASS", dbConn.passwordSecretArn()
);
} else {
// Fallback to H2 embedded
return Map.of("MB_DB_TYPE", "h2");
}
}
}
- Since:
- 3.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordThe engine and version a deployment resolved to, and the supported option it matches.static final recordDatabase connection information provided to applications.static final recordOne engine and version an application can be deployed with.static final recordDatabase requirement specification. -
Method Summary
Modifier and TypeMethodDescriptiondefault intDatabase backup retention requirements.Database initialization SQL scripts to run after creation.Database configuration overrides for specific engines.Database requirement for this application.default Optional<DatabaseSpec.DatabaseOption> findSupportedDatabase(String engine, String version) Finds the supported option matching an engine and version.default intNumber of read replicas for production.default booleanWhether this application requires read replicas for scaling.default DatabaseSpec.DatabaseChoiceresolveDatabase(String applicationId, String engine, String version) Resolves the engine and version a deployment will use againstsupportedDatabases().default List<DatabaseSpec.DatabaseOption> Every engine and version this application can be deployed with, as the choices the Manager and the CLI offer.
-
Method Details
-
databaseRequirement
DatabaseSpec.DatabaseRequirement databaseRequirement()Database requirement for this application.- Returns:
- database requirement (required, optional, or none)
-
databaseInitScripts
-
databaseParameters
-
backupRetentionDays
default int backupRetentionDays()Database backup retention requirements.- Returns:
- backup retention days (1-35), default 7
-
requiresReadReplicas
default boolean requiresReadReplicas()Whether this application requires read replicas for scaling.- Returns:
- true if read replicas should be created
-
readReplicaCount
default int readReplicaCount()Number of read replicas for production.- Returns:
- read replica count (0-5), default 0
-
supportedDatabases
Every engine and version this application can be deployed with, as the choices the Manager and the CLI offer. The default is derived fromdatabaseRequirement(): the requirement's engine at every major version from its minimum upward, marked tested up to its tested maximum. An application that supports more than one engine overrides this and lists each combination.databaseRequirement()stays the primary pairing: the engine and version used when a deployment does not choose one.- Returns:
- the supported combinations, empty when the application has no database
-
findSupportedDatabase
Finds the supported option matching an engine and version. A full version such as8.0.35or15.4matches the option for its major version (8.0,15).- Returns:
- the matching option, or empty when this application does not support the combination
-
resolveDatabase
default DatabaseSpec.DatabaseChoice resolveDatabase(String applicationId, String engine, String version) Resolves the engine and version a deployment will use againstsupportedDatabases(). An unset engine means the requirement's engine; an unset version means the requirement's default for that engine, or the first listed option for any other engine.- Throws:
IllegalArgumentException- when the application does not support the combination
-