From 39cee686412c67e9ab8101ade123f5e1f9c123b1 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Sun, 19 Oct 2025 12:27:55 -0400 Subject: [PATCH 1/3] chore: update ash --- mix.exs | 2 +- mix.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mix.exs b/mix.exs index 5e14da8d..526064c2 100644 --- a/mix.exs +++ b/mix.exs @@ -177,7 +177,7 @@ defmodule AshPostgres.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:ash, ash_version("~> 3.7")}, + {:ash, ash_version("~> 3.7 and >= 3.7.5")}, {:spark, "~> 2.3 and >= 2.3.4"}, {:ash_sql, ash_sql_version("~> 0.3 and >= 0.3.7")}, {:igniter, "~> 0.6 and >= 0.6.29", optional: true}, diff --git a/mix.lock b/mix.lock index c988302d..a40b623c 100644 --- a/mix.lock +++ b/mix.lock @@ -1,10 +1,10 @@ %{ - "ash": {:hex, :ash, "3.7.1", "abb55dee19e0959e529e52fe0622468825ae05400f535484919713e492d9a9e7", [:mix], [{:crux, "~> 0.1.0", [hex: :crux, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.6.29 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.11", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.3.3 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, ">= 0.2.6 and < 1.0.0-0", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4474ce9befe9862d1ed73cadf8a755e836c45a14a7b3b952d02e1a12f2b2e529"}, + "ash": {:hex, :ash, "3.7.5", "91e926d14f51a6b406660bd136c3165316d37f2ce68f0ca6118d7c0e41174f0c", [:mix], [{:crux, ">= 0.1.2 and < 1.0.0-0", [hex: :crux, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.6.29 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.11", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.3.3 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, ">= 0.2.6 and < 1.0.0-0", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "df839ac2321768dde1216e317e5a824a136251699f8837a1e8a9ee4508f7e47a"}, "ash_sql": {:hex, :ash_sql, "0.3.7", "80affa5446075d71deb157c67290685a84b392d723be766bfb684f58fe0143de", [:mix], [{:ash, "~> 3.7", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "ce4d974b8e784171c5a2a62593b3672b42dfd4888fa2239f01a6b32bad769038"}, "benchee": {:hex, :benchee, "1.4.0", "9f1f96a30ac80bab94faad644b39a9031d5632e517416a8ab0a6b0ac4df124ce", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "299cd10dd8ce51c9ea3ddb74bb150f93d25e968f93e4c1fa31698a8e4fa5d715"}, "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, - "credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"}, - "crux": {:hex, :crux, "0.1.1", "94f2f97d2a6079ae3c57f356412bc3b307f9579a80e43f526447b1d508dd4a72", [:mix], [{:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: true]}], "hexpm", "e59d498f038193cbe31e448f9199f5b4c53a4c67cece9922bb839595189dd2b6"}, + "credo": {:hex, :credo, "1.7.13", "126a0697df6b7b71cd18c81bc92335297839a806b6f62b61d417500d1070ff4e", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "47641e6d2bbff1e241e87695b29f617f1a8f912adea34296fb10ecc3d7e9e84f"}, + "crux": {:hex, :crux, "0.1.2", "4441c9e3a34f1e340954ce96b9ad5a2de13ceb4f97b3f910211227bb92e2ca90", [:mix], [{:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: true]}], "hexpm", "563ea3748ebfba9cc078e6d198a1d6a06015a8fae503f0b721363139f0ddb350"}, "db_connection": {:hex, :db_connection, "2.8.1", "9abdc1e68c34c6163f6fb96a96532272d13ad7ca45262156ae8b7ec6d9dc4bec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a61a3d489b239d76f326e03b98794fb8e45168396c925ef25feb405ed09da8fd"}, "decimal": {:hex, :decimal, "2.3.0", "3ad6255aa77b4a3c4f818171b12d237500e63525c2fd056699967a3e7ea20f62", [:mix], [], "hexpm", "a4d66355cb29cb47c3cf30e71329e58361cfcb37c34235ef3bf1d7bf3773aeac"}, "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, From 3c948037c2b5bd6a28e2e481be7e07afecef3573 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Sun, 19 Oct 2025 12:30:18 -0400 Subject: [PATCH 2/3] chore: update mix.lock --- mix.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.lock b/mix.lock index a40b623c..9b2bc487 100644 --- a/mix.lock +++ b/mix.lock @@ -1,6 +1,6 @@ %{ "ash": {:hex, :ash, "3.7.5", "91e926d14f51a6b406660bd136c3165316d37f2ce68f0ca6118d7c0e41174f0c", [:mix], [{:crux, ">= 0.1.2 and < 1.0.0-0", [hex: :crux, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.6.29 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.11", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.3.3 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, ">= 0.2.6 and < 1.0.0-0", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "df839ac2321768dde1216e317e5a824a136251699f8837a1e8a9ee4508f7e47a"}, - "ash_sql": {:hex, :ash_sql, "0.3.7", "80affa5446075d71deb157c67290685a84b392d723be766bfb684f58fe0143de", [:mix], [{:ash, "~> 3.7", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "ce4d974b8e784171c5a2a62593b3672b42dfd4888fa2239f01a6b32bad769038"}, + "ash_sql": {:hex, :ash_sql, "0.3.8", "9f55866149b4fc092eb37c346e0734143f70dbfae8793c86a5a46803c2b47a12", [:mix], [{:ash, "~> 3.7", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "0b58a8191744347bb349ace9affb3effc5ceaf8f1bc572915a5cf2ec4c45b72d"}, "benchee": {:hex, :benchee, "1.4.0", "9f1f96a30ac80bab94faad644b39a9031d5632e517416a8ab0a6b0ac4df124ce", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "299cd10dd8ce51c9ea3ddb74bb150f93d25e968f93e4c1fa31698a8e4fa5d715"}, "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, "credo": {:hex, :credo, "1.7.13", "126a0697df6b7b71cd18c81bc92335297839a806b6f62b61d417500d1070ff4e", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "47641e6d2bbff1e241e87695b29f617f1a8f912adea34296fb10ecc3d7e9e84f"}, From f168e9d9794da8764215ae0193c42f907f0ea05c Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Sun, 19 Oct 2025 22:41:24 -0400 Subject: [PATCH 3/3] chore: fix tests & don't do normal rollbacks with `--tenant` option --- lib/data_layer.ex | 130 +++++++++--------- .../migration_generator.ex | 14 +- .../authors/20251018130654_dev.json.license | 3 - ...018130654_dev.json => 20251020024026.json} | 2 +- ...=> 20251020024026_migrate_resources64.exs} | 4 - 5 files changed, 69 insertions(+), 84 deletions(-) delete mode 100644 priv/resource_snapshots/test_repo/authors/20251018130654_dev.json.license rename priv/resource_snapshots/test_repo/authors/{20251018130654_dev.json => 20251020024026.json} (97%) rename priv/test_repo/migrations/{20251018130654_migrate_resources64_dev.exs => 20251020024026_migrate_resources64.exs} (75%) diff --git a/lib/data_layer.ex b/lib/data_layer.ex index b984c4db..e742f09c 100644 --- a/lib/data_layer.ex +++ b/lib/data_layer.ex @@ -453,72 +453,74 @@ defmodule AshPostgres.DataLayer do migrations_path = AshPostgres.Mix.Helpers.migrations_path([], repo) tenant_migrations_path = AshPostgres.Mix.Helpers.tenant_migrations_path([], repo) - current_migrations = - Ecto.Query.from(row in "schema_migrations", - select: row.version - ) - |> repo.all() - |> Enum.map(&to_string/1) + if "--tenants" not in args do + current_migrations = + Ecto.Query.from(row in "schema_migrations", + select: row.version + ) + |> repo.all() + |> Enum.map(&to_string/1) + + files = + migrations_path + |> Path.join("**/*.exs") + |> Path.wildcard() + |> Enum.sort() + |> Enum.reverse() + |> Enum.filter(fn file -> + Enum.any?(current_migrations, &String.starts_with?(Path.basename(file), &1)) + end) + |> Enum.take(20) + |> Enum.map(&String.trim_leading(&1, migrations_path)) + |> Enum.map(&String.trim_leading(&1, "/")) + + indexed = + files + |> Enum.with_index() + |> Enum.map(fn {file, index} -> "#{index + 1}: #{file}" end) + + to = + Mix.shell().prompt( + """ + How many migrations should be rolled back#{for_repo}? (default: 0) + + Last 20 migration names, with the input you must provide to + rollback up to *and including* that migration: + + #{Enum.join(indexed, "\n")} + Rollback to: + """ + |> String.trim_trailing() + ) + |> String.trim() + |> case do + "" -> + nil - files = - migrations_path - |> Path.join("**/*.exs") - |> Path.wildcard() - |> Enum.sort() - |> Enum.reverse() - |> Enum.filter(fn file -> - Enum.any?(current_migrations, &String.starts_with?(Path.basename(file), &1)) - end) - |> Enum.take(20) - |> Enum.map(&String.trim_leading(&1, migrations_path)) - |> Enum.map(&String.trim_leading(&1, "/")) - - indexed = - files - |> Enum.with_index() - |> Enum.map(fn {file, index} -> "#{index + 1}: #{file}" end) - - to = - Mix.shell().prompt( - """ - How many migrations should be rolled back#{for_repo}? (default: 0) - - Last 20 migration names, with the input you must provide to - rollback up to *and including* that migration: - - #{Enum.join(indexed, "\n")} - Rollback to: - """ - |> String.trim_trailing() - ) - |> String.trim() - |> case do - "" -> - nil - - "0" -> - nil - - n -> - try do - files - |> Enum.at(String.to_integer(n) - 1) - rescue - _ -> - reraise "Required an integer value, got: #{n}", __STACKTRACE__ - end - |> String.split("_", parts: 2) - |> Enum.at(0) - |> String.to_integer() - end + "0" -> + nil - if to do - Mix.Task.run( - "ash_postgres.rollback", - args ++ ["-r", inspect(repo), "--to", to_string(to)] - ) + n -> + try do + files + |> Enum.at(String.to_integer(n) - 1) + rescue + _ -> + reraise "Required an integer value, got: #{n}", __STACKTRACE__ + end + |> String.split("_", parts: 2) + |> Enum.at(0) + |> String.to_integer() + end - Mix.Task.reenable("ash_postgres.rollback") + if to do + Mix.Task.run( + "ash_postgres.rollback", + args ++ ["-r", inspect(repo), "--to", to_string(to)] + ) + + Mix.Task.reenable("ash_postgres.rollback") + end end tenant_files = @@ -599,7 +601,7 @@ defmodule AshPostgres.DataLayer do if to do Mix.Task.run( "ash_postgres.rollback", - args ++ ["--tenants", "-r", inspect(repo), "--to", to] + args ++ ["--tenants", "-r", inspect(repo), "--to", to_string(to)] ) Mix.Task.reenable("ash_postgres.rollback") diff --git a/lib/migration_generator/migration_generator.ex b/lib/migration_generator/migration_generator.ex index 9881818c..425ccb53 100644 --- a/lib/migration_generator/migration_generator.ex +++ b/lib/migration_generator/migration_generator.ex @@ -514,16 +514,6 @@ defmodule AshPostgres.MigrationGenerator do end end - if Mix.env() == :test do - defp with_repo_not_in_test(repo, fun) do - fun.(repo) - end - else - defp with_repo_not_in_test(repo, fun) do - Ecto.Migrator.with_repo(repo, fun) - end - end - defp require_name!(opts) do if !opts.name && !opts.dry_run && !opts.check && !opts.snapshots_only && !opts.dev && !opts.auto_name do @@ -548,7 +538,7 @@ defmodule AshPostgres.MigrationGenerator do end) if tenant? do - with_repo_not_in_test(repo, fn repo -> + Ecto.Migrator.with_repo(repo, fn repo -> for prefix <- repo.all_tenants() do {repo, query, opts} = Ecto.Migration.SchemaMigration.versions(repo, [], prefix) @@ -583,7 +573,7 @@ defmodule AshPostgres.MigrationGenerator do end end) else - with_repo_not_in_test(repo, fn repo -> + Ecto.Migrator.with_repo(repo, fn repo -> {repo, query, opts} = Ecto.Migration.SchemaMigration.versions(repo, [], nil) repo.transaction(fn -> diff --git a/priv/resource_snapshots/test_repo/authors/20251018130654_dev.json.license b/priv/resource_snapshots/test_repo/authors/20251018130654_dev.json.license deleted file mode 100644 index b0a44fab..00000000 --- a/priv/resource_snapshots/test_repo/authors/20251018130654_dev.json.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2019 ash_postgres contributors - -SPDX-License-Identifier: MIT diff --git a/priv/resource_snapshots/test_repo/authors/20251018130654_dev.json b/priv/resource_snapshots/test_repo/authors/20251020024026.json similarity index 97% rename from priv/resource_snapshots/test_repo/authors/20251018130654_dev.json rename to priv/resource_snapshots/test_repo/authors/20251020024026.json index e14b635e..761a9e2a 100644 --- a/priv/resource_snapshots/test_repo/authors/20251018130654_dev.json +++ b/priv/resource_snapshots/test_repo/authors/20251020024026.json @@ -120,7 +120,7 @@ "custom_indexes": [], "custom_statements": [], "has_create_action": true, - "hash": "55CFEDA4CB07DD89D2807B080A6F0E14A0370D7EA0C48E67C36ACAC568137D95", + "hash": "DEDCEFDB71DE94818B8D624B0BFE438AD7AEDC6279FD05B83C11C216E7A0F991", "identities": [], "multitenancy": { "attribute": null, diff --git a/priv/test_repo/migrations/20251018130654_migrate_resources64_dev.exs b/priv/test_repo/migrations/20251020024026_migrate_resources64.exs similarity index 75% rename from priv/test_repo/migrations/20251018130654_migrate_resources64_dev.exs rename to priv/test_repo/migrations/20251020024026_migrate_resources64.exs index ba9e1baf..ff7d63f3 100644 --- a/priv/test_repo/migrations/20251018130654_migrate_resources64_dev.exs +++ b/priv/test_repo/migrations/20251020024026_migrate_resources64.exs @@ -1,7 +1,3 @@ -# SPDX-FileCopyrightText: 2019 ash_postgres contributors -# -# SPDX-License-Identifier: MIT - defmodule AshPostgres.TestRepo.Migrations.MigrateResources64 do @moduledoc """ Updates resources based on their most recent snapshots.