@@ -199,7 +199,11 @@ defmodule AshPostgres.MigrationGenerator do
199199{ primary_key , identities } = merge_primary_keys ( existing_snapshot , snapshots )
200200
201201attributes = Enum . flat_map ( snapshots , & & 1 . attributes )
202- count = Enum . count ( snapshots )
202+
203+ count_with_create =
204+ snapshots
205+ |> Enum . filter ( & & 1 . has_create_action )
206+ |> Enum . count ( )
203207
204208snapshot_identities =
205209snapshots
@@ -208,7 +212,7 @@ defmodule AshPostgres.MigrationGenerator do
208212
209213new_snapshot = % {
210214snapshot
211- | attributes: merge_attributes ( attributes , snapshot . table , count ) ,
215+ | attributes: merge_attributes ( attributes , snapshot . table , count_with_create ) ,
212216identities: snapshot_identities
213217}
214218
@@ -1228,7 +1232,8 @@ defmodule AshPostgres.MigrationGenerator do
12281232table: table || AshPostgres . table ( resource ) ,
12291233repo: AshPostgres . repo ( resource ) ,
12301234multitenancy: multitenancy ( resource ) ,
1231- base_filter: AshPostgres . base_filter_sql ( resource )
1235+ base_filter: AshPostgres . base_filter_sql ( resource ) ,
1236+ has_create_action: has_create_action? ( resource )
12321237}
12331238
12341239hash =
@@ -1239,6 +1244,12 @@ defmodule AshPostgres.MigrationGenerator do
12391244Map . put ( snapshot , :hash , hash )
12401245end
12411246
1247+ defp has_create_action? ( resource ) do
1248+ resource
1249+ |> Ash.Resource.Info . actions ( )
1250+ |> Enum . any? ( & ( & 1 . type == :create ) )
1251+ end
1252+
12421253defp multitenancy ( resource ) do
12431254strategy = Ash.Resource.Info . multitenancy_strategy ( resource )
12441255attribute = Ash.Resource.Info . multitenancy_attribute ( resource )
@@ -1382,6 +1393,7 @@ defmodule AshPostgres.MigrationGenerator do
13821393defp load_snapshot ( json ) do
13831394json
13841395|> Jason . decode! ( keys: :atoms! )
1396+ |> Map . put_new ( :has_create_action , true )
13851397|> Map . update! ( :identities , fn identities ->
13861398Enum . map ( identities , & load_identity / 1 )
13871399end )