Skip to content

Commit ce8fb09

Browse files
authored
fix: warn when resources are skipped due to migrate?: false during mi… (#792)
* fix: warn when resources are skipped due to migrate?: false during migration generation (#585) * Changed the migrate?(false) bug fix error message to only print that some resources were skipped without printing a full list of them. * Broke up the sentences for a better fit for the terminal.
1 parent 5f9c8a4 commit ce8fb09

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

lib/migration_generator/migration_generator.ex

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,21 @@ defmodule AshPostgres.MigrationGenerator do
8585
case extension_migration_files ++ tenant_migration_files ++ migration_files do
8686
[] ->
8787
if !opts.check || opts.dry_run do
88-
Mix.shell().info(
89-
"No changes detected, so no migrations or snapshots have been created."
90-
)
88+
if Enum.empty?(unmanaged_resources) do
89+
Mix.shell().info(
90+
"No changes detected, so no migrations or snapshots have been created."
91+
)
92+
else
93+
Mix.shell().info("""
94+
No changes detected, so no migrations or snapshots have been created.
95+
96+
Note: Some resources have `migrate?` set to `false` and were skipped.
97+
98+
If you expected migrations to be generated for them, remove `migrate?(false)`
99+
from their `postgres` block. Resources generated with `mix ash_postgres.gen.resources
100+
--no-migrations` have `migrate?` set to `false` by default.
101+
""")
102+
end
91103
end
92104

93105
:ok

test/migration_generator_test.exs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6816,4 +6816,55 @@ defmodule AshPostgres.MigrationGeneratorTest do
68166816
refute up =~ "references(:referenced_schema_move_authors"
68176817
end
68186818
end
6819+
describe "resources with migrate? false (#585)" do
6820+
test "warns that resources were skipped due to migrate? false", %{
6821+
snapshot_path: snapshot_path,
6822+
migration_path: migration_path
6823+
} do
6824+
defresource SkippedMigrateResource do
6825+
postgres do
6826+
table "skipped_migrate_resource"
6827+
repo AshPostgres.TestRepo
6828+
migrate? false
6829+
end
6830+
6831+
actions do
6832+
defaults([:read, :create])
6833+
end
6834+
6835+
attributes do
6836+
uuid_primary_key(:id)
6837+
end
6838+
end
6839+
6840+
defdomain([SkippedMigrateResource])
6841+
6842+
# First run: creates extension migrations (unrelated to our resource)
6843+
AshPostgres.MigrationGenerator.generate(Domain,
6844+
snapshot_path: snapshot_path,
6845+
migration_path: migration_path,
6846+
quiet: false,
6847+
format: false,
6848+
auto_name: true
6849+
)
6850+
6851+
flush_mix_shell()
6852+
6853+
# Second run: extensions already exist, so only the migrate? false
6854+
# resource remains — which is skipped, producing "No changes detected"
6855+
AshPostgres.MigrationGenerator.generate(Domain,
6856+
snapshot_path: snapshot_path,
6857+
migration_path: migration_path,
6858+
quiet: false,
6859+
format: false,
6860+
auto_name: true
6861+
)
6862+
6863+
output = shell_output()
6864+
6865+
assert output =~ "No changes detected"
6866+
assert output =~ "migrate?"
6867+
assert output =~ "SkippedMigrateResource"
6868+
end
6869+
end
68196870
end

0 commit comments

Comments
 (0)