@@ -111,6 +111,79 @@ defmodule AshPostgres.MigrationGeneratorTest do
111111 end
112112 end
113113
114+ describe "empty resources" do
115+ setup do
116+ on_exit ( fn ->
117+ File . rm_rf! ( "test_snapshots_path" )
118+ File . rm_rf! ( "test_migration_path" )
119+ end )
120+ end
121+
122+ test "empty resource does not generate migration files" do
123+ defresource EmptyPost , "empty_posts" do
124+ resource do
125+ require_primary_key? ( false )
126+ end
127+
128+ actions do
129+ defaults ( [ :read , :create ] )
130+ end
131+ end
132+
133+ defdomain ( [ EmptyPost ] )
134+
135+ AshPostgres.MigrationGenerator . generate ( Domain ,
136+ snapshot_path: "test_snapshots_path" ,
137+ migration_path: "test_migration_path" ,
138+ quiet: false ,
139+ format: false ,
140+ auto_name: true
141+ )
142+
143+ migration_files =
144+ Path . wildcard ( "test_migration_path/**/*_migrate_resources*.exs" )
145+ |> Enum . reject ( & String . contains? ( & 1 , "extensions" ) )
146+
147+ assert migration_files == [ ]
148+
149+ snapshot_files =
150+ Path . wildcard ( "test_snapshots_path/**/*.json" )
151+ |> Enum . reject ( & String . contains? ( & 1 , "extensions" ) )
152+
153+ assert snapshot_files == [ ]
154+ end
155+
156+ test "resource with only primary key generates migration" do
157+ defresource PostWithId , "posts_with_id" do
158+ attributes do
159+ uuid_primary_key ( :id )
160+ end
161+ end
162+
163+ defdomain ( [ PostWithId ] )
164+
165+ AshPostgres.MigrationGenerator . generate ( Domain ,
166+ snapshot_path: "test_snapshots_path" ,
167+ migration_path: "test_migration_path" ,
168+ quiet: false ,
169+ format: false ,
170+ auto_name: true
171+ )
172+
173+ migration_files =
174+ Path . wildcard ( "test_migration_path/**/*_migrate_resources*.exs" )
175+ |> Enum . reject ( & String . contains? ( & 1 , "extensions" ) )
176+
177+ assert length ( migration_files ) == 1
178+
179+ snapshot_files =
180+ Path . wildcard ( "test_snapshots_path/**/*.json" )
181+ |> Enum . reject ( & String . contains? ( & 1 , "extensions" ) )
182+
183+ assert length ( snapshot_files ) == 1
184+ end
185+ end
186+
114187 describe "creating initial snapshots" do
115188 setup do
116189 on_exit ( fn ->
0 commit comments