Configuration-driven database adapter management.
This namespace provides functionality to read database configuration from config.edn and only load adapters that are marked as :active. This allows for optimized deployments where only required database drivers are loaded.
Key Features:
Usage: (require '[wagoe.platform.shell.adapters.database.config :as db-config])
(db-config/get-active-adapters "dev") ; Get active adapters for dev env (db-config/adapter-active? :postgresql) ; Check if adapter is active
Configuration-driven database adapter management. This namespace provides functionality to read database configuration from config.edn and only load adapters that are marked as :active. This allows for optimized deployments where only required database drivers are loaded. Key Features: - Configuration-driven adapter loading - Environment-specific database configs - Graceful handling of inactive adapters - JDBC driver optimization (only load needed drivers) Usage: (require '[wagoe.platform.shell.adapters.database.config :as db-config]) (db-config/get-active-adapters "dev") ; Get active adapters for dev env (db-config/adapter-active? :postgresql) ; Check if adapter is active
Cache for loaded configurations to avoid repeated file reads
Cache for loaded configurations to avoid repeated file reads
(adapter-active? adapter-type env)Check if a specific adapter type is active in environment
Check if a specific adapter type is active in environment
(clear-config-cache!)Clear configuration cache (useful for testing)
Clear configuration cache (useful for testing)
(config->db-config config-key config)Convert configuration entry to database adapter config
Convert configuration entry to database adapter config
(config-summary env)Get summary of database configuration for environment
Get summary of database configuration for environment
(detect-environment)Detect current environment from various sources
Detect current environment from various sources
(disposable-environment? env)True when env names a database that is safe to destroy or seed.
Callers must pass the environment resolved by detect-environment, not a
direct read of WAG_ENV — the connection uses the full precedence chain
(-Denv > WAG_ENV > ENV > ENVIRONMENT), and a guard that asks a narrower
question than the connection is not a guard.
True when `env` names a database that is safe to destroy or seed. Callers must pass the environment resolved by `detect-environment`, not a direct read of WAG_ENV — the connection uses the full precedence chain (-Denv > WAG_ENV > ENV > ENVIRONMENT), and a guard that asks a narrower question than the connection is not a guard.
Environments whose database may be destroyed or filled with demo data.
An allowlist, deliberately. A denylist naming prod/acc/production lets an unrecognised name — staging, uat, qa, preprod, a typo'd prd — through to a drop or an insert. Anything not known to be disposable is refused.
Single definition on purpose: bb db:seed and bb db:reset both gate on
this, and two copies of a destructive-operation allowlist is exactly the
drift this codebase keeps paying for.
Environments whose database may be destroyed or filled with demo data. An allowlist, deliberately. A denylist naming prod/acc/production lets an unrecognised name — staging, uat, qa, preprod, a typo'd prd — through to a drop or an insert. Anything not known to be disposable is refused. Single definition on purpose: `bb db:seed` and `bb db:reset` both gate on this, and two copies of a destructive-operation allowlist is exactly the drift this codebase keeps paying for.
(get-active-adapters env)Get list of active database adapter types for environment
Get list of active database adapter types for environment
(get-active-adapters-from-config config-map)Get active adapter configurations from config map
Get active adapter configurations from config map
(get-active-db-config)Get the first active database configuration for environment.
This is used by the migration system which operates on a single database. If multiple databases are configured, returns the first one.
Args: None (uses detected environment)
Returns: Database adapter configuration map with :datasource
Throws: Exception if no active database is configured
Get the first active database configuration for environment. This is used by the migration system which operates on a single database. If multiple databases are configured, returns the first one. Args: None (uses detected environment) Returns: Database adapter configuration map with :datasource Throws: Exception if no active database is configured
(get-active-db-configs env)Get database adapter configurations for all active databases in environment
Get database adapter configurations for all active databases in environment
(get-all-database-configs config-map)Get all database configurations (active + inactive) from config map
Get all database configurations (active + inactive) from config map
(get-database-configs env)Get database configurations for environment
Get database configurations for environment
(get-inactive-adapters config-map)Get inactive adapter configurations from config map
Get inactive adapter configurations from config map
(getenv k)Environment variable lookup. Exists as a var (rather than inline interop) so tests can redef it — env vars cannot be modified inside a JVM.
Environment variable lookup. Exists as a var (rather than inline interop) so tests can redef it — env vars cannot be modified inside a JVM.
(load-config env)Load configuration for environment with caching
Load configuration for environment with caching
(merge-configs base-config override-config)Merge two configuration maps
Merge two configuration maps
(print-config-summary env)Print formatted configuration summary for debugging
Print formatted configuration summary for debugging
(valid-adapter-config? adapter-key config)Validate adapter configuration (wrapper for validate-adapter-config)
Validate adapter configuration (wrapper for validate-adapter-config)
(valid-config-structure? config)Validate that config has required structure
Validate that config has required structure
(validate-adapter-config adapter-type config)Validate that an adapter configuration has required keys
Validate that an adapter configuration has required keys
(validate-database-configs env)Validate all database configurations for environment
Validate all database configurations for environment
(with-environment env f)Execute function with specific environment context
Execute function with specific environment context
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |