Skip to content

Commit

Permalink
[api] fix database migration with rails 4
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed Jun 27, 2013
1 parent cc0cc12 commit 5014e6b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/api/lib/tasks/databases.rake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ namespace :db do
case abcs[Rails.env]["adapter"]
when "mysql2"
ActiveRecord::Base.establish_connection(abcs[Rails.env])
structure = ActiveRecord::Base.connection.structure_dump
con = ActiveRecord::Base.connection

sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"

structure = con.select_all(sql, 'SCHEMA').map { |table|
table.delete('Table_type')
sql = "SHOW CREATE TABLE #{con.quote_table_name(table.to_a.first.last)}"
con.exec_query(sql, 'SCHEMA').first['Create Table'] + ";\n\n"
}.join
else
raise "Task not supported by '#{abcs[Rails.env]["adapter"]}'"
end
Expand Down

0 comments on commit 5014e6b

Please sign in to comment.