Skip to content

Commit 1cfb446

Browse files
committed
fix: honor the snapshots_only option
fixes #427
1 parent bd65cb6 commit 1cfb446

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

lib/migration_generator/migration_generator.ex

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ defmodule AshPostgres.MigrationGenerator do
408408
end
409409

410410
create_file(snapshot_file, snapshot_contents, force: true)
411-
create_file(migration_file, contents)
411+
412+
if !opts.snapshots_only do
413+
create_file(migration_file, contents)
414+
end
412415
end
413416
end
414417
end
@@ -469,23 +472,25 @@ defmodule AshPostgres.MigrationGenerator do
469472
exit({:shutdown, 1})
470473
end
471474

472-
operations
473-
|> split_into_migrations()
474-
|> Enum.each(fn operations ->
475-
run_without_transaction? =
476-
Enum.any?(operations, fn
477-
%Operation.AddCustomIndex{index: %{concurrently: true}} ->
478-
true
479-
480-
_ ->
481-
false
482-
end)
483-
475+
if !opts.snapshots_only do
484476
operations
485-
|> organize_operations
486-
|> build_up_and_down()
487-
|> write_migration!(repo, opts, tenant?, run_without_transaction?)
488-
end)
477+
|> split_into_migrations()
478+
|> Enum.each(fn operations ->
479+
run_without_transaction? =
480+
Enum.any?(operations, fn
481+
%Operation.AddCustomIndex{index: %{concurrently: true}} ->
482+
true
483+
484+
_ ->
485+
false
486+
end)
487+
488+
operations
489+
|> organize_operations
490+
|> build_up_and_down()
491+
|> write_migration!(repo, opts, tenant?, run_without_transaction?)
492+
end)
493+
end
489494

490495
create_new_snapshot(snapshots, repo_name(repo), opts, tenant?)
491496
end
@@ -1052,7 +1057,7 @@ defmodule AshPostgres.MigrationGenerator do
10521057
end
10531058

10541059
File.mkdir_p(Path.dirname(snapshot_file))
1055-
File.write!(snapshot_file, snapshot_binary, [])
1060+
create_file(snapshot_file, snapshot_binary, force: true)
10561061

10571062
old_snapshot_folder = Path.join(snapshot_folder, "#{snapshot.table}.json")
10581063

0 commit comments

Comments
 (0)