lib/fx/schema_dumper.rb in fx-0.8.0 vs lib/fx/schema_dumper.rb in fx-0.9.0

- old
+ new

@@ -1,10 +1,50 @@ -require "fx/schema_dumper/function" -require "fx/schema_dumper/trigger" - module Fx # @api private module SchemaDumper - include Function - include Trigger + def tables(stream) + if Fx.configuration.dump_functions_at_beginning_of_schema + functions(stream) + empty_line(stream) + end + + super + + unless Fx.configuration.dump_functions_at_beginning_of_schema + functions(stream) + empty_line(stream) + end + + triggers(stream) + end + + private + + def empty_line(stream) + stream.puts if dumpable_functions_in_database.any? + end + + def functions(stream) + dumpable_functions_in_database.each do |function| + stream.puts(function.to_schema) + end + end + + def triggers(stream) + if dumpable_triggers_in_database.any? + stream.puts + end + + dumpable_triggers_in_database.each do |trigger| + stream.puts(trigger.to_schema) + end + end + + def dumpable_functions_in_database + @_dumpable_functions_in_database ||= Fx.database.functions + end + + def dumpable_triggers_in_database + @_dumpable_triggers_in_database ||= Fx.database.triggers + end end end