Skip to content

Instantly share code, notes, and snippets.

@danshultz
Created January 15, 2014 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danshultz/8437173 to your computer and use it in GitHub Desktop.
Save danshultz/8437173 to your computer and use it in GitHub Desktop.
module ActiveRecord
module ConnectionAdapters
class Mysql2Adapter
alias :build_table_structure :structure_dump
def structure_dump
build_table_structure << build_view_structure << build_function_structure
end
def build_function_structure
# generate sql here
end
def build_view_structure
sql = "SHOW FULL TABLES WHERE Table_type = 'VIEW'"
select_all(sql).inject("") do |structure, table|
table.delete('Table_type')
structure += select_one("SHOW CREATE VIEW #{quote_table_name(table.to_a.first.last)}")["Create View"] + ";\n\n"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment