Module: ViewsInMigrations::SchemaDumper
- Defined in:
- lib/views_in_migrations.rb
Instance Method Summary collapse
-
#table_with_views_in_migrations(table, stream) ⇒ Object
Only output normal tables in the body of the schema.
-
#trailer_with_views_in_migrations(stream) ⇒ Object
After all table definitions, print view definitions.
- #view(view_name, stream) ⇒ Object
- #views(stream) ⇒ Object
Instance Method Details
#table_with_views_in_migrations(table, stream) ⇒ Object
Only output normal tables in the body of the schema
111 112 113 |
# File 'lib/views_in_migrations.rb', line 111 def table_with_views_in_migrations(table, stream) table_without_views_in_migrations(table, stream) unless @connection.table_is_view?(table) end |
#trailer_with_views_in_migrations(stream) ⇒ Object
After all table definitions, print view definitions
116 117 118 119 120 |
# File 'lib/views_in_migrations.rb', line 116 def trailer_with_views_in_migrations(stream) views(stream) trailer_without_views_in_migrations(stream) end |
#view(view_name, stream) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/views_in_migrations.rb', line 132 def view(view_name, stream) stream.puts <<-WARNING ############################################################# # Warning: SchemaDumper cannot determine view dependencies! # # You may have to manually reorder your views to run # # `rake db:schema:load` successfully. # ############################################################# WARNING out = StringIO.new out.puts " create_view #{view_name.inspect}, %{" sql = @connection.define_view(view_name, true) sql.split('\n').each do |line| out.puts " #{line}" end out.puts " }, :force => true\n\n" out.rewind stream.print out.read end |
#views(stream) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/views_in_migrations.rb', line 122 def views(stream) @connection.views.each do |table| stream.puts "if ViewsInMigrations.use_views?(current_database)" view(table,stream) stream.puts "else\n\n" table_without_views_in_migrations(table, stream) stream.puts "end\n\n" end end |