@@ -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
0 commit comments