Skip to content

Commit a35894b

Browse files
committed
improvement: location in spark errors and migration generator fixes
1 parent 702ce5e commit a35894b

8 files changed

+24
-15
lines changed

lib/custom_index.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ defmodule AshPostgres.CustomIndex do
1313
:include,
1414
:nulls_distinct,
1515
:message,
16-
:all_tenants?,
17-
:__spark_metadata__
16+
:all_tenants?
1817
]
1918

20-
defstruct @fields
19+
defstruct @fields ++ [:__spark_metadata__]
2120

2221
def fields, do: @fields
2322

lib/migration_generator/migration_generator.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,6 +3044,7 @@ defmodule AshPostgres.MigrationGenerator do
30443044
identity_index_names[identity.name] ||
30453045
"#{relationship.context[:data_layer][:table]}_#{identity.name}_index"
30463046
)
3047+
|> Map.delete(:__spark_metadata__)
30473048
end)
30483049
end)
30493050
|> Map.update!(:attributes, fn attributes ->
@@ -3057,7 +3058,9 @@ defmodule AshPostgres.MigrationGenerator do
30573058
source_attribute =
30583059
Ash.Resource.Info.attribute(relationship.source, relationship.source_attribute)
30593060

3060-
Map.put(attribute, :references, %{
3061+
attribute
3062+
|> Map.delete(:__spark_metadata__)
3063+
|> Map.put(:references, %{
30613064
destination_attribute: source_attribute.source,
30623065
destination_attribute_default:
30633066
default(
@@ -3489,7 +3492,8 @@ defmodule AshPostgres.MigrationGenerator do
34893492

34903493
@uuid_functions [&Ash.UUID.generate/0, &Ecto.UUID.generate/0]
34913494

3492-
defp default(%{name: name, default: default, type: type}, resource, _repo) when is_function(default) do
3495+
defp default(%{name: name, default: default, type: type}, resource, _repo)
3496+
when is_function(default) do
34933497
configured_default(resource, name) ||
34943498
cond do
34953499
default in @uuid_functions ->

lib/statement.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ defmodule AshPostgres.Statement do
55
:name,
66
:up,
77
:down,
8-
:code?,
9-
:__spark_metadata__
8+
:code?
109
]
1110

12-
defstruct @fields
11+
defstruct @fields ++ [:__spark_metadata__]
1312

1413
def fields, do: @fields
1514

lib/verifiers/ensure_table_or_polymorphic.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ defmodule AshPostgres.Verifiers.EnsureTableOrPolymorphic do
2424
end
2525
```
2626
""",
27-
path: [:postgres, :table]
27+
path: [:postgres, :table],
28+
location: Spark.Dsl.Transformer.get_section_anno(dsl, [:postgres])
2829
end
2930
end
3031
end

lib/verifiers/prevent_attribute_multitenancy_and_non_full_match_type.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ defmodule AshPostgres.Verifiers.PreventAttributeMultitenancyAndNonFullMatchType
2323
2424
The reference #{inspect(resource)}.#{reference.relationship} can't have `match_type: :#{reference.match_type}` because it's referencing another multitenant resource with attribute strategy using a non-primary key index, which requires using `match_type: :full`.
2525
""",
26-
path: [:postgres, :references, reference.relationship]
26+
path: [:postgres, :references, reference.relationship],
27+
location: Spark.Dsl.Transformer.get_section_anno(dsl, [:postgres, :references])
2728
else
2829
:ok
2930
end

lib/verifiers/prevent_multidimensional_array_aggregates.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ defmodule AshPostgres.Verifiers.PreventMultidimensionalArrayAggregates do
3535
3636
Postgres does not support multidimensional arrays with differing lengths internally. In the future we may be able to remove this restriction
3737
for the `:first` type aggregate, but likely never for `:list`. In the meantime, you will have to use a custom calculation to get this data.
38-
"""
38+
""",
39+
location: Ash.Resource.Info.aggregate(resource, aggregate.name) |> Spark.Dsl.Entity.anno()
3940

4041
_ ->
4142
:ok

lib/verifiers/validate_identity_index_names.ex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ defmodule AshPostgres.Verifiers.ValidateIdentityIndexNames do
1414
module: Verifier.get_persisted(dsl, :module),
1515
message: """
1616
Identity #{identity} has a name that is too long. Names must be 63 characters or less.
17-
"""
17+
""",
18+
location: Spark.Dsl.Transformer.get_opt_anno(dsl, [:postgres, :identity_index_names], identity)
1819
end
1920
end)
2021

@@ -36,7 +37,8 @@ defmodule AshPostgres.Verifiers.ValidateIdentityIndexNames do
3637
Multiple identities would result in the same index name: #{name}
3738
3839
Identities: #{inspect(Enum.map(identities, & &1.name))}
39-
"""
40+
""",
41+
location: Spark.Dsl.Transformer.get_section_anno(dsl, [:postgres, :identity_index_names])
4042

4143
{name, [identity]} ->
4244
if String.length(name) > 63 do
@@ -51,7 +53,8 @@ defmodule AshPostgres.Verifiers.ValidateIdentityIndexNames do
5153
postgres do
5254
identity_index_names #{identity.name}: "a_shorter_name"
5355
end
54-
"""
56+
""",
57+
location: Spark.Dsl.Entity.anno(identity)
5558
end
5659
end)
5760
end

lib/verifiers/validate_references.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ defmodule AshPostgres.Verifiers.ValidateReferences do
1212
path: [:postgres, :references, reference.relationship],
1313
module: Verifier.get_persisted(dsl, :module),
1414
message:
15-
"Found reference configuration for relationship `#{reference.relationship}`, but no such relationship exists"
15+
"Found reference configuration for relationship `#{reference.relationship}`, but no such relationship exists",
16+
location: Spark.Dsl.Transformer.get_section_anno(dsl, [:postgres, :references])
1617
end
1718
end)
1819

0 commit comments

Comments
 (0)