Skip to content

Commit

Permalink
#11 autoformat code with emacs magic
Browse files Browse the repository at this point in the history
  • Loading branch information
bearmug committed Jan 30, 2019
1 parent bab663c commit 0fed0b7
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 163 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ all: clean code-checks test cover

travis: all coveralls

local: all format

clean:
$(REBAR) clean

Expand All @@ -22,3 +24,6 @@ cover:

coveralls:
$(REBAR) as test coveralls send

format:
$(REBAR) fmt
54 changes: 27 additions & 27 deletions elvis.config
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
[
{
elvis,
[
{config,
#{src_dirs => ["src"],
rules => [{elvis_style, line_length, [120]},
{elvis_style, no_tabs, []},
{elvis_style, macro_names, []},
{elvis_style, macro_module_names, []},
{elvis_style, operator_spaces, [{right, ","},
{right, "++"},
{left, "++"}]},
{elvis_style, nesting_level, [3]},
{elvis_style, god_modules, [25]},
{elvis_style, no_if_expression, []},
{elvis_style, invalid_dynamic_call, [elvis]},
{elvis_style, used_ignored_variable, []},
{elvis_style, no_behavior_info, []},
{
elvis_style,
module_naming_convention,
["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
{
elvis,
[
{config,
#{src_dirs => ["src"],
rules => [{elvis_style, line_length, [120]},
{elvis_style, no_tabs, []},
{elvis_style, macro_names, []},
{elvis_style, macro_module_names, []},
{elvis_style, operator_spaces, [{right, ","},
{right, "++"},
{left, "++"}]},
{elvis_style, nesting_level, [3]},
{elvis_style, god_modules, [25]},
{elvis_style, no_if_expression, []},
{elvis_style, invalid_dynamic_call, [elvis]},
{elvis_style, used_ignored_variable, []},
{elvis_style, no_behavior_info, []},
{
elvis_style,
module_naming_convention,
["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
}
]
}
}
]
]
}
}
]
}
].
].
40 changes: 20 additions & 20 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{profiles, [
{test, [
{deps, [
{erlexec, {git, "https://github.com/saleyn/erlexec.git", {ref, "576fb5d"}}}
]},
{eunit_opts , [verbose]},
{cover_enabled , true},
{cover_print_enabled , true},
{cover_export_enabled , true},
{coveralls_coverdata , "_build/test/cover/ct.coverdata"},
{coveralls_service_name , "travis-ci"},
{plugins , [coveralls]}
]},
{lint, [
{plugins, [rebar3_lint]}
]}
]}.

{test, [
{deps, [
{erlexec, {git, "https://github.com/saleyn/erlexec.git", {ref, "576fb5d"}}}
]},
{eunit_opts , [verbose]},
{cover_enabled , true},
{cover_print_enabled , true},
{cover_export_enabled , true},
{coveralls_coverdata , "_build/test/cover/ct.coverdata"},
{coveralls_service_name , "travis-ci"},
{plugins , [coveralls]}
]},
{lint, [
{plugins, [rebar3_lint]}
]}
]}.
{plugins, [rebar3_fmt]}.
{dialyzer,
[
{plt_location, "_build/plt"}
]}.
[
{plt_location, "_build/plt"}
]}.
12 changes: 6 additions & 6 deletions rebar.config.script
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
case os:getenv("TRAVIS") of
"true" ->
JobId = os:getenv("TRAVIS_JOB_ID"),
lists:keystore(coveralls_service_job_id, 1, CONFIG, {coveralls_service_job_id, JobId});
_ ->
CONFIG
end.
"true" ->
JobId = os:getenv("TRAVIS_JOB_ID"),
lists:keystore(coveralls_service_job_id, 1, CONFIG, {coveralls_service_job_id, JobId});
_ ->
CONFIG
end.
6 changes: 3 additions & 3 deletions src/dialect_postgres.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
-export([init/0, migrations_names/0, save_migration/2, latest_existing_version/0]).

init() ->
"CREATE TABLE IF NOT EXISTS database_migrations_history (
"CREATE TABLE IF NOT EXISTS database_migrations_history (
version INTEGER NOT NULL PRIMARY KEY,
filename TEXT NOT NULL,
creation_timestamp TIMESTAMP NOT NULL DEFAULT NOW()
)".
)".

migrations_names() ->
"SELECT version, filename FROM database_migrations_history".
Expand All @@ -18,4 +18,4 @@ save_migration(Version, Filename) ->
[Version, Filename])).

latest_existing_version() ->
"SELECT max(version) FROM database_migrations_history".
"SELECT max(version) FROM database_migrations_history".
68 changes: 34 additions & 34 deletions src/engine.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@
-type error() :: {error, Type :: atom(), Details :: any()}.

-spec migrate(
Path :: nonempty_string(),
FTx :: fun((F) -> ok | error()),
FQuery :: fun((nonempty_string()) -> ok | list(string()) | integer() | error())) -> R
when
F :: fun(() -> ok | error()),
R :: fun(() -> ok | error()).
Path :: nonempty_string(),
FTx :: fun((F) -> ok | error()),
FQuery :: fun((nonempty_string()) -> ok | list(string()) | integer() | error())) -> R
when
F :: fun(() -> ok | error()),
R :: fun(() -> ok | error()).
migrate(Path, FTx, FQuery) ->
ok = FQuery(dialect_postgres:init()),
fun() -> FTx(flatten(
map(
find_migrations(Path, FQuery),
fun({V, F}) -> do_migration(Path, FQuery, {V, F}) end),
fun(M)-> ok = M() end))
end.
ok = FQuery(dialect_postgres:init()),
fun() -> FTx(flatten(
map(
find_migrations(Path, FQuery),
fun({V, F}) -> do_migration(Path, FQuery, {V, F}) end),
fun(M)-> ok = M() end))
end.

do_migration(Path, FQuery, {Version, FileName}) ->
Version = FQuery(dialect_postgres:latest_existing_version()) + 1,
ScriptPath = filename:join(Path, FileName),
compose(
fun() -> file:read_file(ScriptPath) end,
fun({ok, ScriptBody}) ->
ok = FQuery(ScriptBody),
ok = FQuery(dialect_postgres:save_migration(Version, FileName))
end
).
Version = FQuery(dialect_postgres:latest_existing_version()) + 1,
ScriptPath = filename:join(Path, FileName),
compose(
fun() -> file:read_file(ScriptPath) end,
fun({ok, ScriptBody}) ->
ok = FQuery(ScriptBody),
ok = FQuery(dialect_postgres:save_migration(Version, FileName))
end
).

find_migrations(ScriptsLocation, FQuery) ->
MigrationsDone = sets:from_list(FQuery(dialect_postgres:migrations_names())),
compose(
fun() -> file:list_dir_all(ScriptsLocation) end,
fun({ok, Files}) -> lists:filter(
fun(N) -> not sets:is_element(N, MigrationsDone) end,
lists:keysort(1, [
{list_to_integer(head(string:split(F, "_"))), F} || F <- Files]))
end
).
MigrationsDone = sets:from_list(FQuery(dialect_postgres:migrations_names())),
compose(
fun() -> file:list_dir_all(ScriptsLocation) end,
fun({ok, Files}) -> lists:filter(
fun(N) -> not sets:is_element(N, MigrationsDone) end,
lists:keysort(1, [
{list_to_integer(head(string:split(F, "_"))), F} || F <- Files]))
end
).

head([H|_]) -> H.

compose(F1, F2) ->
fun() -> F2(F1()) end.
fun() -> F2(F1()) end.

map(Generate, Map) ->
fun() -> [Map(R) || R <- Generate()] end.
fun() -> [Map(R) || R <- Generate()] end.

flatten(Generate, Flatten) ->
fun() -> [Flatten(R) || R <- Generate()] end.
fun() -> [Flatten(R) || R <- Generate()] end.
22 changes: 11 additions & 11 deletions src/pure_migrations.app.src
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{application, pure_migrations,
[{description, "Database Pure Migration Tool"},
{vsn, "0.1"},
{licenses, ["MIT"]},
{registered, []},
{modules, []},
{applications, [
kernel,
stdlib
]},
{env, []}
]}.
[{description, "Database Pure Migration Tool"},
{vsn, "0.1"},
{licenses, ["MIT"]},
{registered, []},
{modules, []},
{applications, [
kernel,
stdlib
]},
{env, []}
]}.

0 comments on commit 0fed0b7

Please sign in to comment.