Module: Spectacles::SchemaDumper
- Defined in:
- lib/spectacles/schema_dumper.rb
Class Method Summary collapse
- .dump_materialized_view(stream, connection, view_name) ⇒ Object
- .dump_materialized_views(dumper, stream, connection) ⇒ Object
- .dump_view(stream, connection, view_name) ⇒ Object
- .dump_views(stream, connection) ⇒ Object
- .format_option_hash(hash) ⇒ Object
- .format_option_value(value) ⇒ Object
- .skip_view?(view) ⇒ Boolean
Class Method Details
.dump_materialized_view(stream, connection, view_name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/spectacles/schema_dumper.rb', line 34 def self.dump_materialized_view(stream, connection, view_name) definition, = connection.materialized_view_build_query(view_name) [:force] = true stream.print <<-CREATEVIEW create_materialized_view #{view_name.to_sym.inspect}, #{format_option_hash()} do <<-SQL #{definition} SQL end CREATEVIEW end |
.dump_materialized_views(dumper, stream, connection) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/spectacles/schema_dumper.rb', line 12 def self.dump_materialized_views(dumper, stream, connection) unless Spectacles.config.enable_schema_dump == false if connection.supports_materialized_views? connection.materialized_views.sort.each do |view| next if skip_view?(view) dump_materialized_view(stream, connection, view) dumper.send(:indexes, view, stream) end end end end |
.dump_view(stream, connection, view_name) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/spectacles/schema_dumper.rb', line 24 def self.dump_view(stream, connection, view_name) stream.print <<-CREATEVIEW create_view :#{view_name}, :force => true do "#{connection.view_build_query(view_name)}" end CREATEVIEW end |
.dump_views(stream, connection) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/spectacles/schema_dumper.rb', line 3 def self.dump_views(stream, connection) unless Spectacles.config.enable_schema_dump == false connection.views.sort.each do |view| next if skip_view?(view) dump_view(stream, connection, view) end end end |
.format_option_hash(hash) ⇒ Object
48 49 50 51 52 |
# File 'lib/spectacles/schema_dumper.rb', line 48 def self.format_option_hash(hash) hash.map do |key, value| "#{key}: #{format_option_value(value)}" end.join(", ") end |
.format_option_value(value) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/spectacles/schema_dumper.rb', line 54 def self.format_option_value(value) case value when Hash then "{ #{format_option_hash(value)} }" when /^\d+$/ then value.to_i when /^\d+\.\d+$/ then value.to_f when true, false then value.inspect else raise "can't format #{value.inspect}" end end |
.skip_view?(view) ⇒ Boolean
64 65 66 |
# File 'lib/spectacles/schema_dumper.rb', line 64 def self.skip_view?(view) Spectacles.config.skip_views.any? { |item| item === view } end |