Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{erl_opts, [debug_info, warnings_as_errors]}.

{deps, [
{kura, {git, "https://github.com/Taure/kura.git", {tag, "v2.0.0"}}},
{kura, {git, "https://github.com/Taure/kura.git", {tag, "v2.0.2"}}},
{esqlite, "~> 0.9"}
]}.

Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[{<<"esqlite">>,{pkg,<<"esqlite">>,<<"0.9.0">>},0},
{<<"kura">>,
{git,"https://github.com/Taure/kura.git",
{ref,"78f71e2e954e11c2f1cf49112dc8123c8dd8cf95"}},
{ref,"de3fd745fc588ff9384e513b7254ddf28dcf11da"}},
0},
{<<"telemetry">>,{pkg,<<"telemetry">>,<<"1.4.1">>},1}]}.
[
Expand Down
6 changes: 6 additions & 0 deletions test/kura_sqlite_e2e_test_repo.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-module(kura_sqlite_e2e_test_repo).
-behaviour(kura_repo).

-export([otp_app/0]).

otp_app() -> kura_sqlite_e2e_test_app.
85 changes: 85 additions & 0 deletions test/kura_sqlite_migrator_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
-module(kura_sqlite_migrator_SUITE).
-moduledoc """
End-to-end migration through `kura_migrator:migrate/1` against an
in-memory SQLite database. Pins the SQLite migration runtime path
that asobi-CT covers for Postgres but no app exercises for SQLite.
""".

-include_lib("common_test/include/ct.hrl").
-include_lib("stdlib/include/assert.hrl").

-export([all/0, init_per_suite/1, end_per_suite/1]).
-export([
migrate_creates_table/1,
migrate_records_version_in_schema_migrations/1,
rollback_drops_table/1
]).

-define(REPO, kura_sqlite_e2e_test_repo).
-define(APP, kura_sqlite_e2e_test_app).
-define(POOL, kura_sqlite_e2e_pool).
-define(VERSION, 20260510000000).

all() ->
[
migrate_creates_table,
migrate_records_version_in_schema_migrations,
rollback_drops_table
].

init_per_suite(Config) ->
%% Make sure backend modules are loaded before kura_app:resolve_backends
%% looks them up.
{module, _} = code:ensure_loaded(kura_backend_sqlite),
application:set_env(kura, repos, #{
?REPO => #{
backend => kura_backend_sqlite,
database => <<":memory:">>,
pool_size => 1
}
}),
application:set_env(kura, ensure_database, false),
{ok, _} = application:ensure_all_started(kura),
%% Synthetic app so kura_migrator:discover_migrations/1 finds the test
%% migration via application:get_key(?APP, modules).
AppSpec =
{application, ?APP, [
{description, "test app for kura_sqlite_migrator_SUITE"},
{vsn, "0.0.1"},
{modules, [?REPO, m20260510000000_e2e_create_widgets]},
{registered, []},
{applications, [kernel, stdlib]}
]},
ok = application:load(AppSpec),
Config.

end_per_suite(_Config) ->
application:unload(?APP),
kura_pool_sqlite:stop_pool(?REPO),
application:stop(kura),
application:unset_env(kura, repos),
application:unset_env(kura, ensure_database),
ok.

migrate_creates_table(_Config) ->
{ok, [?VERSION]} = kura_migrator:migrate(?REPO),
%% Verify the widgets table is queryable.
Result = kura_db:query(?REPO, ~"SELECT name FROM widgets WHERE 1=0", []),
?assertMatch(#{rows := []}, Result).

migrate_records_version_in_schema_migrations(_Config) ->
%% migrate_creates_table already applied, so this run should be a no-op.
{ok, []} = kura_migrator:migrate(?REPO),
Result = kura_db:query(
?REPO, ~"SELECT version FROM schema_migrations ORDER BY version", []
),
?assertMatch(#{rows := [#{version := ?VERSION}]}, Result).

rollback_drops_table(_Config) ->
{ok, [?VERSION]} = kura_migrator:rollback(?REPO),
Result = kura_db:query(
?REPO,
~"SELECT name FROM sqlite_master WHERE type='table' AND name='widgets'",
[]
),
?assertMatch(#{rows := []}, Result).
19 changes: 19 additions & 0 deletions test/m20260510000000_e2e_create_widgets.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-module(m20260510000000_e2e_create_widgets).
-behaviour(kura_migration).

-include_lib("kura/include/kura.hrl").

-export([up/0, down/0]).

up() ->
[
{create_table, ~"widgets", [
#kura_column{name = id, type = id, primary_key = true, nullable = false},
#kura_column{name = name, type = string, nullable = false},
#kura_column{name = active, type = boolean, default = true},
#kura_column{name = data, type = jsonb}
]}
].

down() ->
[{drop_table, ~"widgets"}].
Loading