Advertisement
Guest User

Untitled

a guest
May 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require_relative 'config/environment'
  4.  
  5. path = ARGV.shift || raise("specify migration as first argument")
  6.  
  7. require_relative path
  8.  
  9. filename = File.basename(path, ".rb")
  10. timestamp, name = filename.split("_", 2)
  11.  
  12. name = name.camelcase
  13.  
  14. ActiveRecord::Migration.verbose = false
  15.  
  16. module Wrapper
  17. def execute(sql, *args)
  18. if sql =~ /^ALTER\ TABLE|((CREATE|DROP) (TABLE|VIEW))|INSERT/i
  19. puts sql.gsub(/`/, '') + ";"
  20. else
  21. super
  22. end
  23. end
  24. end
  25.  
  26. ActiveRecord::Base.connection # Needed to load Mysql2Adapter
  27.  
  28. ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(Wrapper)
  29.  
  30. migration = name.constantize
  31.  
  32. migration.migrate(:up)
  33.  
  34. ActiveRecord::SchemaMigration.create!(:version => timestamp.to_s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement