kura_repo behaviour (kura v1.19.2)
View SourceBehaviour for defining a repository (database connection).
Implement otp_app/0 to tell Kura which application owns the repo's
migrations.
-module(my_repo).
-behaviour(kura_repo).
-export([otp_app/0]).
otp_app() -> my_app.Configure the database connection under the kura application env.
Kura starts the pgo pool automatically during application startup:
[{kura, [
{repo, my_repo},
{host, "localhost"},
{port, 5432},
{database, "my_db"},
{user, "postgres"},
{password, "secret"},
{pool_size, 10}
]}].For backward compatibility, Kura also supports per-app config via
application:get_env(OtpApp, RepoModule). The kura app env is checked
first.
Optionally implement init/1 to modify config at runtime — useful for reading
secrets from files, environment variables, or external services:
-module(my_repo).
-behaviour(kura_repo).
-export([otp_app/0, init/1]).
otp_app() -> my_app.
init(Config) ->
Config#{
password => list_to_binary(os:getenv("DB_PASSWORD", "postgres"))
}.
Summary
Functions
Read the repo configuration from application environment.