mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-19 21:13:19 +12:00
parent
3ac292617e
commit
38bf555867
4 changed files with 43 additions and 1 deletions
|
@ -12,6 +12,7 @@ locals_without_parens = [
|
|||
]
|
||||
|
||||
[
|
||||
import_deps: [:ash],
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
|
||||
locals_without_parens: locals_without_parens,
|
||||
export: [
|
||||
|
|
|
@ -16,11 +16,20 @@ defmodule AshPostgres.MigrationGenerator do
|
|||
quiet: false,
|
||||
format: true,
|
||||
dry_run: false,
|
||||
check_generated: false,
|
||||
drop_columns: false
|
||||
|
||||
def generate(apis, opts \\ []) do
|
||||
apis = List.wrap(apis)
|
||||
opts = struct(__MODULE__, opts)
|
||||
|
||||
opts =
|
||||
case struct(__MODULE__, opts) do
|
||||
%{check_generated: true} = opts ->
|
||||
%{opts | dry_run: true}
|
||||
|
||||
opts ->
|
||||
opts
|
||||
end
|
||||
|
||||
{tenant_snapshots, snapshots} =
|
||||
apis
|
||||
|
@ -68,6 +77,8 @@ defmodule AshPostgres.MigrationGenerator do
|
|||
:ok
|
||||
|
||||
operations ->
|
||||
if opts.check_generated, do: exit({:shutdown, 1})
|
||||
|
||||
operations
|
||||
|> sort_operations()
|
||||
|> streamline()
|
||||
|
|
|
@ -16,6 +16,7 @@ defmodule Mix.Tasks.AshPostgres.GenerateMigrations do
|
|||
* `quiet` - messages for file creations will not be printed
|
||||
* `no_format` - files that are created will not be formatted with the code formatter
|
||||
* `dry_run` - no files are created, instead the new migration is printed
|
||||
* `check_migrated` - no files are created, returns an exit(1) code if the current snapshots and resources don't fit
|
||||
|
||||
#### Snapshots
|
||||
|
||||
|
@ -77,6 +78,7 @@ defmodule Mix.Tasks.AshPostgres.GenerateMigrations do
|
|||
quiet: :boolean,
|
||||
no_format: :boolean,
|
||||
dry_run: :boolean,
|
||||
check_migrated: :boolean,
|
||||
drop_columns: :boolean
|
||||
]
|
||||
)
|
||||
|
|
|
@ -388,4 +388,32 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
~S[add :views, :integer]
|
||||
end
|
||||
end
|
||||
|
||||
describe "--check_migrated option" do
|
||||
setup do
|
||||
defposts do
|
||||
attributes do
|
||||
uuid_primary_key :id
|
||||
attribute(:title, :string)
|
||||
end
|
||||
end
|
||||
|
||||
defapi([Post])
|
||||
|
||||
[api: Api]
|
||||
end
|
||||
|
||||
test "returns code(1) if snapshots and resources don't fit", %{api: api} do
|
||||
assert catch_exit(
|
||||
AshPostgres.MigrationGenerator.generate(api,
|
||||
snapshot_path: "test_snapshot_path",
|
||||
migration_path: "test_migration_path",
|
||||
check_generated: true
|
||||
)
|
||||
) == {:shutdown, 1}
|
||||
|
||||
refute File.exists?(Path.wildcard("test_migration_path2/**/*_migrate_resources*.exs"))
|
||||
refute File.exists?(Path.wildcard("test_snapshots_path2/test_repo/posts/*.json"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue