Skip to content

ensure multi-schema dumping in Rails 8.1.0 doesn't dump the same objects for all schemas#177

Merged
teoljungberg merged 1 commit intoteoljungberg:masterfrom
agrobbin:rails-8-1-0-rump-dump-schemas
Oct 31, 2025
Merged

ensure multi-schema dumping in Rails 8.1.0 doesn't dump the same objects for all schemas#177
teoljungberg merged 1 commit intoteoljungberg:masterfrom
agrobbin:rails-8-1-0-rump-dump-schemas

Conversation

@agrobbin
Copy link
Contributor

In Rails 8.1.0, bin/rails db:schema:dump now knows how to dump multiple schemas (rails/rails#50020). To ensure we don't dump the same functions / triggers for each schema, we need to stop memoizing Fx.database.{functions,triggers}.

This should be fully backwards compatible to previous Rails versions, as we still only call each of those methods once per schema dumping invocation, it just now works if schema dumping is invoked multiple times.

@teoljungberg
Copy link
Owner

teoljungberg commented Oct 28, 2025

Can you add a test to document this behavior under rails 8.1?

…cts for all schemas

In Rails 8.1.0, `bin/rails db:schema:dump` now knows how to dump multiple schemas (rails/rails#50020). To ensure we don't dump the same functions / triggers for each schema, we need to stop memoizing `Fx.database.{functions,triggers}`.

This should be fully backwards compatible to previous Rails versions, as we still only call each of those methods once per schema dumping invocation, it just now works if schema dumping is invoked multiple times.
@agrobbin agrobbin force-pushed the rails-8-1-0-rump-dump-schemas branch from 46cea95 to 010ade7 Compare October 28, 2025 16:55
@agrobbin
Copy link
Contributor Author

@teoljungberg I definitely should have included that from the start, sorry about that. Just added a test case for multiple schemas.

@teoljungberg
Copy link
Owner

Can we confirm that this fails on Rails 8.1 without the patch? Just for sake of coverage?

@agrobbin
Copy link
Contributor Author

@teoljungberg I did exactly that locally, writing this test and running it on master:

$ bin/rake
DEPRECATION WARNING: `config.active_support.to_time_preserves_timezone` is deprecated and will be removed in Rails 8.2 (called from <top (required)> at /Users/alexrobbin/Code/Forks/fx/spec/dummy/config/environment.rb:5)

Randomized with seed 7588
....F....................................................................................

Failures:

  1) Fx::SchemaDumper when there are functions / triggers in multiple schemas dumps functions and triggers for multiple schemas
     Failure/Error: expect(output.scan("create_function :test_public_func").size).to eq(1)

       expected: 1
            got: 2

       (compared using ==)
     # ./spec/fx/schema_dumper_spec.rb:162:in 'block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:20:in 'block (2 levels) in <top (required)>'

Finished in 0.28327 seconds (files took 0.73187 seconds to load)
89 examples, 1 failure

Failed examples:

rspec ./spec/fx/schema_dumper_spec.rb:121 # Fx::SchemaDumper when there are functions / triggers in multiple schemas dumps functions and triggers for multiple schemas

Randomized with seed 7588

@teoljungberg
Copy link
Owner

Excellent, thank you for confirming!

@teoljungberg teoljungberg merged commit a77ebcd into teoljungberg:master Oct 31, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants