Skip to content

Commit 5ae7e79

Browse files
Merge branch 'main' of https://github.com/m0rt3nlund/ash_postgres into Partitioning-support
2 parents 5a4a262 + 7d53f47 commit 5ae7e79

File tree

29 files changed

+1872
-55
lines changed

29 files changed

+1872
-55
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
version: 2
1+
---
22
updates:
3-
- package-ecosystem: mix
4-
directory: "/"
5-
versioning-strategy: lockfile-only
6-
schedule:
7-
interval: weekly
8-
day: thursday
3+
- directory: /
94
groups:
10-
production-dependencies:
11-
dependency-type: production
125
dev-dependencies:
136
dependency-type: development
7+
production-dependencies:
8+
dependency-type: production
9+
package-ecosystem: mix
10+
schedule:
11+
day: thursday
12+
interval: monthly
13+
versioning-strategy: lockfile-only
14+
version: 2

CHANGELOG.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,66 @@ See [Conventional Commits](https://www.conventionalcommits.org) for commit guide
55

66
<!-- changelog -->
77

8+
## [v2.6.17](https://github.com/ash-project/ash_postgres/compare/v2.6.16...v2.6.17) (2025-08-31)
9+
10+
11+
12+
13+
### Bug Fixes:
14+
15+
* resolve a typo in pending dev migration error message (#608) by Sheharyar Naseer
16+
17+
## [v2.6.16](https://github.com/ash-project/ash_postgres/compare/v2.6.15...v2.6.16) (2025-08-21)
18+
19+
20+
21+
22+
### Improvements:
23+
24+
* Unrelated aggregates (#606) by Zach Daniel
25+
26+
## [v2.6.15](https://github.com/ash-project/ash_postgres/compare/v2.6.14...v2.6.15) (2025-08-07)
27+
28+
29+
30+
31+
### Bug Fixes:
32+
33+
* Use new attribute source in down migration (#604) by Anatolij Werle
34+
35+
* always set disable_async, and remove log level config by Zach Daniel
36+
37+
## [v2.6.14](https://github.com/ash-project/ash_postgres/compare/v2.6.13...v2.6.14) (2025-07-29)
38+
39+
40+
41+
42+
### Bug Fixes:
43+
44+
* deduplicate identity keys by Zach Daniel
45+
46+
## [v2.6.13](https://github.com/ash-project/ash_postgres/compare/v2.6.12...v2.6.13) (2025-07-27)
47+
48+
49+
50+
51+
### Bug Fixes:
52+
53+
* ensure tenant prefix is set only for resources with context multitenancy (#600) by Emad Shaaban
54+
55+
## [v2.6.12](https://github.com/ash-project/ash_postgres/compare/v2.6.11...v2.6.12) (2025-07-25)
56+
57+
58+
59+
60+
### Bug Fixes:
61+
62+
* ensure tenant is set on query for updates by Zach Daniel
63+
64+
### Improvements:
65+
66+
* do not create snapshots for resources that have no attributes #571 (#599) by horberlan
67+
868
## [v2.6.11](https://github.com/ash-project/ash_postgres/compare/v2.6.10...v2.6.11) (2025-07-17)
969

1070

lib/data_layer.ex

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ defmodule AshPostgres.DataLayer do
747747
when type in [:count, :sum, :first, :list, :avg, :max, :min, :exists, :custom],
748748
do: true
749749

750+
def can?(_, {:aggregate, :unrelated}), do: true
750751
def can?(_, :aggregate_filter), do: true
751752
def can?(_, :aggregate_sort), do: true
752753
def can?(_, :calculate), do: true
@@ -919,8 +920,12 @@ defmodule AshPostgres.DataLayer do
919920
end
920921

921922
@impl true
922-
def set_tenant(_resource, query, tenant) do
923-
{:ok, Map.put(Ecto.Query.put_query_prefix(query, to_string(tenant)), :__tenant__, tenant)}
923+
def set_tenant(resource, query, tenant) do
924+
if Ash.Resource.Info.multitenancy_strategy(resource) == :context do
925+
{:ok, Map.put(Ecto.Query.put_query_prefix(query, to_string(tenant)), :__tenant__, tenant)}
926+
else
927+
{:ok, query}
928+
end
924929
end
925930

926931
@impl true
@@ -3165,6 +3170,14 @@ defmodule AshPostgres.DataLayer do
31653170
changeset.context
31663171
)
31673172
|> pkey_filter(changeset.data)
3173+
|> then(fn query ->
3174+
if changeset.tenant do
3175+
set_tenant(resource, query, changeset.tenant)
3176+
|> elem(1)
3177+
else
3178+
query
3179+
end
3180+
end)
31683181
|> then(fn query ->
31693182
Map.put(
31703183
query,

lib/migration_generator/migration_generator.ex

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ defmodule AshPostgres.MigrationGenerator do
460460
461461
You have migrations remaining that were generated with the --dev flag.
462462
463-
Run `mix ash.codegen <name>` to remove the dev migraitons and replace them
464-
with production ready migrations.
463+
Run `mix ash.codegen <name>` to remove the dev migrations and replace them
464+
with production-ready migrations.
465465
""")
466466

467467
exit({:shutdown, 1})
@@ -1989,6 +1989,17 @@ defmodule AshPostgres.MigrationGenerator do
19891989
end)
19901990
end
19911991

1992+
defp resource_has_meaningful_content?(snapshot) do
1993+
[
1994+
snapshot.attributes,
1995+
snapshot.identities,
1996+
snapshot.custom_indexes,
1997+
snapshot.custom_statements,
1998+
snapshot.check_constraints
1999+
]
2000+
|> Enum.any?(&Enum.any?/1)
2001+
end
2002+
19922003
defp do_fetch_operations(snapshot, existing_snapshot, opts, acc \\ [])
19932004

19942005
defp do_fetch_operations(
@@ -2002,35 +2013,45 @@ defmodule AshPostgres.MigrationGenerator do
20022013
end
20032014

20042015
defp do_fetch_operations(snapshot, nil, opts, acc) do
2005-
empty_snapshot = %{
2006-
attributes: [],
2007-
identities: [],
2008-
schema: nil,
2009-
custom_indexes: [],
2010-
custom_statements: [],
2011-
check_constraints: [],
2012-
table: snapshot.table,
2013-
repo: snapshot.repo,
2014-
base_filter: nil,
2015-
empty?: true,
2016-
multitenancy: %{
2017-
attribute: nil,
2018-
strategy: nil,
2019-
global: nil
2020-
}
2021-
}
2022-
2023-
do_fetch_operations(snapshot, empty_snapshot, opts, [
2024-
%Operation.CreateTable{
2016+
if resource_has_meaningful_content?(snapshot) do
2017+
empty_snapshot = %{
2018+
attributes: [],
2019+
identities: [],
2020+
schema: nil,
2021+
custom_indexes: [],
2022+
custom_statements: [],
2023+
check_constraints: [],
20252024
table: snapshot.table,
2026-
schema: snapshot.schema,
20272025
repo: snapshot.repo,
2028-
multitenancy: snapshot.multitenancy,
2029-
old_multitenancy: empty_snapshot.multitenancy,
2030-
partitioning: snapshot.partitioning
2026+
base_filter: nil,
2027+
empty?: true,
2028+
multitenancy: %{
2029+
attribute: nil,
2030+
strategy: nil,
2031+
global: nil
2032+
}
20312033
}
2032-
| acc
2033-
])
2034+
2035+
do_fetch_operations(snapshot, empty_snapshot, opts, [
2036+
%Operation.CreateTable{
2037+
table: snapshot.table,
2038+
schema: snapshot.schema,
2039+
repo: snapshot.repo,
2040+
multitenancy: snapshot.multitenancy,
2041+
old_multitenancy: empty_snapshot.multitenancy,
2042+
partitioning: snapshot.partitioning
2043+
}
2044+
| acc
2045+
])
2046+
else
2047+
if !opts.quiet do
2048+
Logger.info(
2049+
"Skipping migration for empty resource: #{snapshot.table} (no attributes, identities, indexes, statements, or constraints)"
2050+
)
2051+
end
2052+
2053+
acc
2054+
end
20342055
end
20352056

20362057
defp do_fetch_operations(snapshot, old_snapshot, opts, acc) do

lib/migration_generator/operation.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do
130130

131131
def index_keys(keys, all_tenants?, multitenancy) do
132132
if multitenancy.strategy == :attribute and not all_tenants? do
133-
[multitenancy.attribute | keys]
133+
Enum.uniq([multitenancy.attribute | keys])
134134
else
135135
keys
136136
end
@@ -752,7 +752,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do
752752
up(%{
753753
op
754754
| old_attribute: op.new_attribute,
755-
new_attribute: op.old_attribute,
755+
new_attribute: Map.put(op.old_attribute, :source, op.new_attribute.source),
756756
old_multitenancy: op.multitenancy,
757757
multitenancy: op.old_multitenancy
758758
})

lib/mix/tasks/ash_postgres.install.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,8 @@ if Code.ensure_loaded?(Igniter) do
341341
Ecto.Adapters.SQL.Sandbox
342342
)
343343
|> Igniter.Project.Config.configure_new("test.exs", otp_app, [repo, :pool_size], 10)
344-
|> Igniter.Project.Config.configure_new("test.exs", :ash, [:disable_async?], true)
345-
|> Igniter.Project.Config.configure_new("test.exs", :logger, [:level], :warning)
346344
end
345+
|> Igniter.Project.Config.configure_new("test.exs", :ash, [:disable_async?], true)
347346
end
348347

349348
defp setup_data_case(igniter) do

mix.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule AshPostgres.MixProject do
55
The PostgreSQL data layer for Ash Framework
66
"""
77

8-
@version "2.6.11"
8+
@version "2.6.17"
99

1010
def project do
1111
[
@@ -166,8 +166,8 @@ defmodule AshPostgres.MixProject do
166166
# Run "mix help deps" to learn about dependencies.
167167
defp deps do
168168
[
169-
{:ash, ash_version("~> 3.5 and >= 3.5.13")},
170-
{:ash_sql, ash_sql_version("~> 0.2 and >= 0.2.72")},
169+
{:ash, ash_version("~> 3.5 and >= 3.5.35")},
170+
{:ash_sql, ash_sql_version("~> 0.2 and >= 0.2.90")},
171171
{:igniter, "~> 0.6 and >= 0.6.14", optional: true},
172172
{:ecto_sql, "~> 3.13"},
173173
{:ecto, "~> 3.13"},

0 commit comments

Comments
 (0)