Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve conflict with other schema dumpers #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/schema_plus/core/active_record/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ def self.prepended(base)

def dump(stream)
@dump = SchemaDump.new(self)
super stream

# If some other gem has a SchemaDumper, and it is higher than us in inheritance chain,
# it still can write something into a "real" stream that would evade our redefined methods.
# Tentatively consider that all it wrote can go to "header" (though it might be too naive).
temp_stream = StringIO.new
super temp_stream
@dump.header += temp_stream.string

@dump.assemble(stream)
end

Expand Down Expand Up @@ -54,7 +61,15 @@ def types(_)

def tables(_)
SchemaMonkey::Middleware::Dumper::Tables.start(dumper: self, connection: @connection, dump: @dump) do |env|
super nil
# Other gems SchemaDumpers might redefine tables and, besides using methods like `table` inside
# (which we override), they might also write directly to a stream.
# For examples, https://github.com/bibendi/activerecord-postgres_enum/blob/v2.1.0/lib/active_record/postgres_enum/schema_dumper.rb
# This gem overrides `tables` to drop `create_enum` statements into the stream before table definitions.
#
# Tentatively consider whatever is written this way as part of the header, though it might be too naive.
stream = StringIO.new
super stream
@dump.header += stream.string
end
end

Expand Down
Loading