Merge pull request #50336 from fatkodima/schema_dumper-dump-global-out

Change `SchemaDumper.dump` default stream to `$stdout`
This commit is contained in:
Jean Boussier 2023-12-14 16:41:23 +01:00 committed by GitHub
commit 970126e07e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -41,7 +41,7 @@ module ActiveRecord
cattr_accessor :unique_ignore_pattern, default: /^uniq_rails_[0-9a-f]{10}$/
class << self
def dump(connection = ActiveRecord::Base.connection, stream = STDOUT, config = ActiveRecord::Base)
def dump(connection = ActiveRecord::Base.connection, stream = $stdout, config = ActiveRecord::Base)
connection.create_schema_dumper(generate_options(config)).dump(stream)
stream
end

View File

@ -5,19 +5,21 @@ module SchemaDumpingHelper
connection = ActiveRecord::Base.connection
old_ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
ActiveRecord::SchemaDumper.ignore_tables = connection.data_sources - tables
stream = StringIO.new
ActiveRecord::SchemaDumper.dump(connection, stream)
stream.string
output, = capture_io do
ActiveRecord::SchemaDumper.dump(connection)
end
output
ensure
ActiveRecord::SchemaDumper.ignore_tables = old_ignore_tables
end
def dump_all_table_schema(ignore_tables = [], connection: ActiveRecord::Base.connection)
old_ignore_tables, ActiveRecord::SchemaDumper.ignore_tables = ActiveRecord::SchemaDumper.ignore_tables, ignore_tables
stream = StringIO.new
ActiveRecord::SchemaDumper.dump(connection, stream)
stream.string
output, = capture_io do
ActiveRecord::SchemaDumper.dump(connection)
end
output
ensure
ActiveRecord::SchemaDumper.ignore_tables = old_ignore_tables
end