Module: ActiveRecordShards::SchemaDumperExtension
- Defined in:
- lib/active_record_shards/schema_dumper_extension.rb
Instance Method Summary collapse
Instance Method Details
#dump(stream) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_record_shards/schema_dumper_extension.rb', line 5 def dump(stream) stream = super(stream) original_connection = @connection if ActiveRecord::Base.supports_sharding? ActiveRecord::Base.on_first_shard do @connection = ActiveRecord::Base.connection shard_header(stream) extensions(stream) tables(stream) shard_trailer(stream) end end stream ensure @connection = original_connection end |
#shard_header(stream) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_record_shards/schema_dumper_extension.rb', line 24 def shard_header(stream) define_params = @version ? "version: #{@version}" : "" stream.puts <<~HEADER # This section generated by active_record_shards ActiveRecord::Base.on_all_shards do ActiveRecord::Schema.define(#{define_params}) do HEADER end |
#shard_trailer(stream) ⇒ Object
38 39 40 |
# File 'lib/active_record_shards/schema_dumper_extension.rb', line 38 def shard_trailer(stream) stream.puts "end\nend" end |