Skip to content

Commit 2ceb31f

Browse files
author
ttt161
committed
minor improvments
1 parent 0217692 commit 2ceb31f

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

apps/bender/priv/migrations/sequence/1770994589112-copy-sequence.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
-export([perform/2]).
44

55
-spec perform(_, _) -> _.
6-
perform(Connection, _MigrationOpts) ->
7-
perform_batch(Connection, 0, 100).
6+
perform(Connection, MigrationOpts) ->
7+
BatchSize = proplists:get_value(batch_size, MigrationOpts, 5000),
8+
perform_batch(Connection, 0, BatchSize).
89

910
perform_batch(Connection, Offset, Limit) ->
1011
SQL = "SELECT process_id, aux_state FROM bender_sequence_processes ORDER BY created_at OFFSET $1 LIMIT $2",

apps/bender/src/bender.erl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
-export_type([schema/0]).
2222

2323
-define(DB_REF, bender).
24+
-define(DEFAULT_MIGRATION_OPTS, [{batch_size, 5000}]).
2425

2526
%% API
2627

@@ -163,6 +164,11 @@ db_init(machinery) ->
163164
ok.
164165

165166
db_init(MigrationsDir, DbOpts) ->
166-
{ok, _} = epg_migrator:perform("generator", DbOpts, [], filename:join([MigrationsDir, "generator"])),
167-
{ok, _} = epg_migrator:perform("sequence", DbOpts, [], filename:join([MigrationsDir, "sequence"])),
167+
MigrationOpts = application:get_env(bender, migration_opts, ?DEFAULT_MIGRATION_OPTS),
168+
logger:info("migrations for generator start"),
169+
{ok, _} = epg_migrator:perform("generator", DbOpts, MigrationOpts, filename:join([MigrationsDir, "generator"])),
170+
logger:info("migrations for generator success"),
171+
logger:info("migrations for sequence start"),
172+
{ok, _} = epg_migrator:perform("sequence", DbOpts, MigrationOpts, filename:join([MigrationsDir, "sequence"])),
173+
logger:info("migrations for sequence success"),
168174
ok.

0 commit comments

Comments
 (0)