Current section

Files

Jump to
cigogne src cigogne@types.erl
Raw

src/cigogne@types.erl

-module(cigogne@types).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/cigogne/types.gleam").
-export([print_migrate_error/1]).
-export_type([connection_config/0, config/0, schema_config/0, migrate_error/0, migration/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type connection_config() :: env_var_config |
{url_config, binary()} |
{pog_config, pog:config()} |
{connection_config, pog:connection()}.
-type config() :: {config,
connection_config(),
binary(),
binary(),
schema_config(),
binary(),
binary()}.
-type schema_config() :: {schema_config, boolean(), binary()}.
-type migrate_error() :: {env_var_error, binary()} |
{url_error, binary()} |
{file_error, binary()} |
{create_folder_error, binary()} |
{pattern_error, binary()} |
{file_name_error, binary()} |
{compound_error, list(migrate_error())} |
{content_error, binary(), binary()} |
{p_g_o_transaction_error, pog:transaction_error(binary())} |
{p_g_o_query_error, pog:query_error()} |
no_result_error |
{schema_query_error, binary()} |
no_migration_to_apply_error |
no_migration_to_rollback_error |
{migration_not_found_error, gleam@time@timestamp:timestamp(), binary()} |
{date_parse_error, binary()} |
{file_hash_changed, gleam@time@timestamp:timestamp(), binary()} |
{name_too_long_error, binary()} |
{actor_start_error, gleam@otp@actor:start_error()}.
-type migration() :: {migration,
binary(),
gleam@time@timestamp:timestamp(),
binary(),
list(binary()),
list(binary()),
binary()}.
-file("src/cigogne/types.gleam", 75).
?DOC(" Print a MigrateError to the stderr\n").
-spec print_migrate_error(migrate_error()) -> nil.
print_migrate_error(Error) ->
case Error of
{compound_error, Suberrors} ->
gleam_stdlib:println_error(<<"["/utf8>>),
gleam@list:each(Suberrors, fun print_migrate_error/1),
gleam_stdlib:println_error(<<"]"/utf8>>);
{content_error, Path, Message} ->
gleam_stdlib:println_error(
<<<<<<<<"At ["/utf8, Path/binary>>/binary,
"]: Content wasn't right <"/utf8>>/binary,
Message/binary>>/binary,
">"/utf8>>
);
{env_var_error, Name} ->
gleam_stdlib:println_error(
<<"Couldn't find env var "/utf8, Name/binary>>
);
{file_error, Path@1} ->
gleam_stdlib:println_error(
<<<<"Couldn't access file at path ["/utf8, Path@1/binary>>/binary,
"]\nCheck the file or the parent folders exist and that you have the right permissions."/utf8>>
);
{file_name_error, Path@2} ->
gleam_stdlib:println_error(
<<<<"Migration filenames should have the format <MigrationNumber>-<MigrationName>.sql ! Got: ["/utf8,
Path@2/binary>>/binary,
"]"/utf8>>
);
no_result_error ->
gleam_stdlib:println_error(
<<"Got no result from DB (can't get last applied migration)"/utf8>>
);
{p_g_o_query_error, Suberror} ->
gleam_stdlib:println_error(
cigogne@internal@utils:describe_query_error(Suberror)
);
{p_g_o_transaction_error, Suberror@1} ->
gleam_stdlib:println_error(
cigogne@internal@utils:describe_transaction_error(Suberror@1)
);
{pattern_error, Message@1} ->
gleam_stdlib:println_error(Message@1);
{url_error, Url} ->
gleam_stdlib:println_error(
<<"Database URL badly formatted: "/utf8, Url/binary>>
);
{schema_query_error, Err} ->
gleam_stdlib:println_error(
<<"Error while querying schema : "/utf8, Err/binary>>
);
no_migration_to_apply_error ->
gleam_stdlib:println_error(<<"No migration to apply !"/utf8>>);
no_migration_to_rollback_error ->
gleam_stdlib:println_error(
<<"No user migration has been applied !"/utf8>>
);
{migration_not_found_error, Ts, Name@1} ->
gleam_stdlib:println_error(
<<<<<<<<"Migration not found [timestamp: "/utf8,
(begin
_pipe = Ts,
gleam@time@timestamp:to_rfc3339(
_pipe,
{duration, 0, 0}
)
end)/binary>>/binary,
", name: "/utf8>>/binary,
Name@1/binary>>/binary,
"]"/utf8>>
);
{date_parse_error, Date} ->
gleam_stdlib:println_error(
<<"Date couldn't be properly parsed: "/utf8, Date/binary>>
);
{file_hash_changed, Migration_ts, Migration_name} ->
gleam_stdlib:println_error(
<<<<<<<<"File contents of migration have changed since last applied [timestamp: "/utf8,
(begin
_pipe@1 = Migration_ts,
gleam@time@timestamp:to_rfc3339(
_pipe@1,
{duration, 0, 0}
)
end)/binary>>/binary,
", name: "/utf8>>/binary,
Migration_name/binary>>/binary,
"]"/utf8>>
);
{name_too_long_error, Name@2} ->
gleam_stdlib:println_error(
<<"Migration name should be no more than 255 characters: "/utf8,
Name@2/binary>>
);
{create_folder_error, Path@3} ->
gleam_stdlib:println_error(
<<<<"Couldn't create folder at path ["/utf8, Path@3/binary>>/binary,
"]"/utf8>>
);
{actor_start_error, Error@1} ->
case Error@1 of
{init_exited, _} ->
gleam_stdlib:println_error(
<<"Actor init exited unexpectedly"/utf8>>
);
{init_failed, Reason} ->
gleam_stdlib:println_error(
<<"Actor init failed: "/utf8, Reason/binary>>
);
init_timeout ->
gleam_stdlib:println_error(
<<"Connection actor init timed out"/utf8>>
)
end
end.