From e141a64e672760fc2cad1b8d2468fb030c2db90c Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Thu, 1 Oct 2026 10:58:42 +0800 Subject: [PATCH 1/7] fix: remove leftover postgres-isms --- test/migration_generator_test.exs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/migration_generator_test.exs b/test/migration_generator_test.exs index 0f131da..4301661 100644 --- a/test/migration_generator_test.exs +++ b/test/migration_generator_test.exs @@ -424,13 +424,11 @@ defmodule AshSqlite.MigrationGeneratorTest do assert [_file1, file2] = Enum.sort(Path.wildcard("#{migration_path}/**/*_migrate_resources*.exs")) - contents = File.read!(file2) - - assert contents =~ - ~S|drop_if_exists unique_index(:posts, [:title], name: "posts_title_index")| - - assert contents =~ - ~S|create unique_index(:posts, [:title], name: "titles_r_unique_dawg")| + assert File.read!(file2) =~ + """ + drop_if_exists unique_index(:posts, [:title], name: "posts_title_index") + create unique_index(:posts, [:title], name: "titles_r_unique_dawg") + """ end test "when adding a field, it adds the field", %{ From c4c941949e7af4e6d29748894acc456e8483bd3b Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Mon, 5 Oct 2026 12:03:38 +0800 Subject: [PATCH 2/7] fix: use repo/2 consistently Fixes: cf33460fc0 ("chore: better functional repo support, add guide") https://github.com/ash-project/ash_postgres/commit/db8255e5b --- lib/data_layer.ex | 3 ++- lib/migration_generator/migration_generator.ex | 14 +++++++------- lib/mix/helpers.ex | 4 +++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/data_layer.ex b/lib/data_layer.ex index 87871e0..e9d16b0 100644 --- a/lib/data_layer.ex +++ b/lib/data_layer.ex @@ -462,7 +462,8 @@ defmodule AshSqlite.DataLayer do other_data_layer = Ash.DataLayer.data_layer(other_resource) data_layer == other_data_layer and - AshSqlite.DataLayer.Info.repo(resource) == AshSqlite.DataLayer.Info.repo(other_resource) + AshSqlite.DataLayer.Info.repo(resource, :read) == + AshSqlite.DataLayer.Info.repo(other_resource, :read) end def can?(_resource, {:lateral_join, _}) do diff --git a/lib/migration_generator/migration_generator.ex b/lib/migration_generator/migration_generator.ex index 21acbab..b3dd58c 100644 --- a/lib/migration_generator/migration_generator.ex +++ b/lib/migration_generator/migration_generator.ex @@ -92,7 +92,7 @@ defmodule AshSqlite.MigrationGenerator do all_resources |> Enum.filter(fn resource -> Ash.DataLayer.data_layer(resource) == AshSqlite.DataLayer && - AshSqlite.DataLayer.Info.repo(resource) == repo && + AshSqlite.DataLayer.Info.repo(resource, :mutate) == repo && (is_nil(only_resources) || resource in only_resources) end) |> Enum.flat_map(&get_snapshots(&1, all_resources)) @@ -2157,7 +2157,7 @@ defmodule AshSqlite.MigrationGenerator do defp pad(i), do: to_string(i) def get_snapshots(resource, all_resources) do - Code.ensure_compiled!(AshSqlite.DataLayer.Info.repo(resource)) + Code.ensure_compiled!(AshSqlite.DataLayer.Info.repo(resource, :mutate)) if AshSqlite.DataLayer.Info.polymorphic?(resource) do all_resources @@ -2198,7 +2198,7 @@ defmodule AshSqlite.MigrationGenerator do default( source_attribute, relationship.destination, - AshSqlite.DataLayer.Info.repo(relationship.destination) + AshSqlite.DataLayer.Info.repo(relationship.destination, :mutate) ), deferrable: false, match_tenant?: false, @@ -2230,7 +2230,7 @@ defmodule AshSqlite.MigrationGenerator do table: table || AshSqlite.DataLayer.Info.table(resource), custom_indexes: custom_indexes(resource), custom_statements: custom_statements(resource), - repo: AshSqlite.DataLayer.Info.repo(resource), + repo: AshSqlite.DataLayer.Info.repo(resource, :mutate), multitenancy: multitenancy(resource), base_filter: AshSqlite.DataLayer.Info.base_filter_sql(resource), has_create_action: has_create_action?(resource), @@ -2280,7 +2280,7 @@ defmodule AshSqlite.MigrationGenerator do end defp attributes(resource, table) do - repo = AshSqlite.DataLayer.Info.repo(resource) + repo = AshSqlite.DataLayer.Info.repo(resource, :mutate) ignored = AshSqlite.DataLayer.Info.migration_ignore_attributes(resource) || [] resource @@ -2553,8 +2553,8 @@ defmodule AshSqlite.MigrationGenerator do defp foreign_key?(relationship) do Ash.DataLayer.data_layer(relationship.source) == AshSqlite.DataLayer && - AshSqlite.DataLayer.Info.repo(relationship.source) == - AshSqlite.DataLayer.Info.repo(relationship.destination) + AshSqlite.DataLayer.Info.repo(relationship.source, :mutate) == + AshSqlite.DataLayer.Info.repo(relationship.destination, :mutate) end defp identities(resource) do diff --git a/lib/mix/helpers.ex b/lib/mix/helpers.ex index 78b16c3..e5a929d 100644 --- a/lib/mix/helpers.ex +++ b/lib/mix/helpers.ex @@ -62,7 +62,9 @@ defmodule AshSqlite.Mix.Helpers do end resources - |> Enum.map(&AshSqlite.DataLayer.Info.repo/1) + |> Enum.flat_map( + &[AshSqlite.DataLayer.Info.repo(&1, :read), AshSqlite.DataLayer.Info.repo(&1, :mutate)] + ) |> Enum.uniq() |> case do [] -> From 44e9c6c393414290c85a0b77d618284dfd7a4609 Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Mon, 5 Oct 2026 12:27:42 +0800 Subject: [PATCH 3/7] fix: properly configure `polymorphic_name` option https://github.com/ash-project/ash_postgres/commit/a60dbf172 --- lib/data_layer.ex | 4 ++-- lib/data_layer/info.ex | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/data_layer.ex b/lib/data_layer.ex index e9d16b0..649c884 100644 --- a/lib/data_layer.ex +++ b/lib/data_layer.ex @@ -133,9 +133,9 @@ defmodule AshSqlite.DataLayer do "For polymorphic resources, configures the on_update behavior of the automatically generated foreign keys to source tables." ], polymorphic_name: [ - type: {:one_of, [:update, :nilify, :nothing, :restrict]}, + type: :string, doc: - "For polymorphic resources, configures the on_update behavior of the automatically generated foreign keys to source tables." + "For polymorphic resources, then index name to use for the foreign key to the source table." ] ] } diff --git a/lib/data_layer/info.ex b/lib/data_layer/info.ex index 98ea859..d6d7548 100644 --- a/lib/data_layer/info.ex +++ b/lib/data_layer/info.ex @@ -120,7 +120,7 @@ defmodule AshSqlite.DataLayer.Info do @doc "The configured polymorphic_reference_name for a resource" def polymorphic_name(resource) do - Extension.get_opt(resource, [:sqlite, :references], :polymorphic_on_delete, nil, true) + Extension.get_opt(resource, [:sqlite, :references], :polymorphic_name, nil, true) end @doc "The configured polymorphic? for a resource" From 6b32ba91ebdcb6130bc72ee5268f1454300ae7e8 Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Mon, 5 Oct 2026 12:51:27 +0800 Subject: [PATCH 4/7] feat: expose min_sqlite_version on DataLayer.Info --- lib/data_layer/info.ex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/data_layer/info.ex b/lib/data_layer/info.ex index d6d7548..e77781c 100644 --- a/lib/data_layer/info.ex +++ b/lib/data_layer/info.ex @@ -66,6 +66,28 @@ defmodule AshSqlite.DataLayer.Info do defp resource_module(dsl_state), do: Spark.Dsl.Transformer.get_persisted(dsl_state, :module) + @doc "Checks a version requirement against the resource's repo's sqlite version" + def sqlite_version_matches?(resource, requirement) do + resource + |> min_sqlite_version() + |> Version.match?(requirement) + end + + @doc "Gets the resource's repo's sqlite version" + def min_sqlite_version(resource) do + case repo(resource, :read).min_sqlite_version() do + %Version{} = version -> + version + + string when is_binary(string) -> + IO.warn( + "Got a `string` for min_sqlite_version, expected a `Version` struct. Got: #{inspect(string)}. Please call `Version.parse!` before returning the value." + ) + + Version.parse!(string) + end + end + @doc "The configured table for a resource" def table(resource) do Extension.get_opt(resource, [:sqlite], :table, nil, true) From b308491535e7d12cc79e975d0d34463ee0b03dbd Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Mon, 5 Oct 2026 12:54:15 +0800 Subject: [PATCH 5/7] Improvement: mark (i)like functions as predicates https://github.com/ash-project/ash_postgres/commit/a9d38e91 --- lib/functions/ilike.ex | 2 +- lib/functions/like.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/functions/ilike.ex b/lib/functions/ilike.ex index c87cc54..f3b0c85 100644 --- a/lib/functions/ilike.ex +++ b/lib/functions/ilike.ex @@ -7,7 +7,7 @@ defmodule AshSqlite.Functions.ILike do Maps to the builtin sqlite function `ilike`. """ - use Ash.Query.Function, name: :ilike + use Ash.Query.Function, name: :ilike, predicate?: true def args, do: [[:string, :string]] end diff --git a/lib/functions/like.ex b/lib/functions/like.ex index 978c8a5..b8c3eda 100644 --- a/lib/functions/like.ex +++ b/lib/functions/like.ex @@ -7,7 +7,7 @@ defmodule AshSqlite.Functions.Like do Maps to the builtin sqlite function `like`. """ - use Ash.Query.Function, name: :like + use Ash.Query.Function, name: :like, predicate?: true def args, do: [[:string, :string]] end From 25b098b0815ad1ed649d138879519ae0c78788e7 Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Mon, 5 Oct 2026 12:55:54 +0800 Subject: [PATCH 6/7] fix: add more type signatures for like/ilike https://github.com/ash-project/ash_postgres/commit/c931f6a987bf0813511c2dfd5590d7b2335ea537 --- lib/functions/ilike.ex | 8 +++++++- lib/functions/like.ex | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/functions/ilike.ex b/lib/functions/ilike.ex index f3b0c85..c0554b2 100644 --- a/lib/functions/ilike.ex +++ b/lib/functions/ilike.ex @@ -9,5 +9,11 @@ defmodule AshSqlite.Functions.ILike do use Ash.Query.Function, name: :ilike, predicate?: true - def args, do: [[:string, :string]] + def args, + do: [ + [:string, :string], + [:string, :ci_string], + [:ci_string, :string], + [:ci_string, :ci_string] + ] end diff --git a/lib/functions/like.ex b/lib/functions/like.ex index b8c3eda..d728a80 100644 --- a/lib/functions/like.ex +++ b/lib/functions/like.ex @@ -9,5 +9,11 @@ defmodule AshSqlite.Functions.Like do use Ash.Query.Function, name: :like, predicate?: true - def args, do: [[:string, :string]] + def args, + do: [ + [:string, :string], + [:string, :ci_string], + [:ci_string, :string], + [:ci_string, :ci_string] + ] end From 1bca8031bbff4ca90ad13bb69c8e3feb7b7d1a2a Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Sat, 10 Oct 2026 14:03:09 +0800 Subject: [PATCH 7/7] feat: Make MigrationGenerator accept atoms https://github.com/ash-project/ash_postgres/commit/a8b7f3b3e7a59e695812caa255750f98f9323750 --- .../migration_generator.ex | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/migration_generator/migration_generator.ex b/lib/migration_generator/migration_generator.ex index b3dd58c..3107e1e 100644 --- a/lib/migration_generator/migration_generator.ex +++ b/lib/migration_generator/migration_generator.ex @@ -2723,7 +2723,7 @@ defmodule AshSqlite.MigrationGenerator do |> Map.update!(:custom_indexes, &load_custom_indexes/1) |> Map.put_new(:custom_statements, []) |> Map.update!(:custom_statements, &load_custom_statements/1) - |> Map.update!(:repo, &String.to_atom/1) + |> Map.update!(:repo, &maybe_to_atom/1) |> Map.put_new(:multitenancy, %{ attribute: nil, strategy: nil, @@ -2744,14 +2744,14 @@ defmodule AshSqlite.MigrationGenerator do defp load_custom_statements(statements) do Enum.map(statements || [], fn statement -> - Map.update!(statement, :name, &String.to_atom/1) + Map.update!(statement, :name, &maybe_to_atom/1) end) end defp load_multitenancy(multitenancy) do multitenancy - |> Map.update!(:strategy, fn strategy -> strategy && String.to_atom(strategy) end) - |> Map.update!(:attribute, fn attribute -> attribute && String.to_atom(attribute) end) + |> Map.update!(:strategy, fn strategy -> strategy && maybe_to_atom(strategy) end) + |> Map.update!(:attribute, fn attribute -> attribute && maybe_to_atom(attribute) end) end defp load_attribute(attribute, table) do @@ -2774,9 +2774,9 @@ defmodule AshSqlite.MigrationGenerator do attribute = if Map.has_key?(attribute, :name) do - Map.put(attribute, :source, String.to_atom(attribute.name)) + Map.put(attribute, :source, maybe_to_atom(attribute.name)) else - Map.update!(attribute, :source, &String.to_atom/1) + Map.update!(attribute, :source, &maybe_to_atom/1) end attribute @@ -2803,7 +2803,7 @@ defmodule AshSqlite.MigrationGenerator do ) |> Map.delete(:ignore) |> rewrite(:ignore?, :ignore) - |> Map.update!(:destination_attribute, &String.to_atom/1) + |> Map.update!(:destination_attribute, &maybe_to_atom/1) |> Map.put_new(:deferrable, false) |> Map.update!(:deferrable, fn "initially" -> :initially @@ -2814,8 +2814,8 @@ defmodule AshSqlite.MigrationGenerator do |> Map.put_new(:match_tenant?, false) |> Map.put_new(:on_delete, nil) |> Map.put_new(:on_update, nil) - |> Map.update!(:on_delete, &(&1 && String.to_atom(&1))) - |> Map.update!(:on_update, &(&1 && String.to_atom(&1))) + |> Map.update!(:on_delete, &(&1 && maybe_to_atom(&1))) + |> Map.update!(:on_update, &(&1 && maybe_to_atom(&1))) |> Map.put( :name, Map.get(references, :name) || "#{table}_#{attribute.source}_fkey" @@ -2871,15 +2871,15 @@ defmodule AshSqlite.MigrationGenerator do end defp load_type(type) do - String.to_atom(type) + maybe_to_atom(type) end defp load_identity(identity, table) do identity - |> Map.update!(:name, &String.to_atom/1) + |> Map.update!(:name, &maybe_to_atom/1) |> Map.update!(:keys, fn keys -> keys - |> Enum.map(&String.to_atom/1) + |> Enum.map(&maybe_to_atom/1) |> Enum.sort() end) |> add_index_name(table) @@ -2889,4 +2889,7 @@ defmodule AshSqlite.MigrationGenerator do defp add_index_name(%{name: name} = index, table) do Map.put_new(index, :index_name, "#{table}_#{name}_unique_index") end + + defp maybe_to_atom(value) when is_atom(value), do: value + defp maybe_to_atom(value), do: String.to_atom(value) end