Skip to content

Instantly share code, notes, and snippets.

@jwright
Created December 10, 2014 23:41
Show Gist options
  • Save jwright/0420ba0adb163f6b4d89 to your computer and use it in GitHub Desktop.
Save jwright/0420ba0adb163f6b4d89 to your computer and use it in GitHub Desktop.
Rake task to generate an empty Sequel migration
namespace :db do
desc "Create a migration with NAME="
task :create_migration do
name = ENV["NAME"]
if name.nil?
puts 'You must specify a migration name (e.g. rake db:create_migration NAME=create_events)!'
exit false
end
content = "Sequel.migration do\n change do\n end\nend"
timestamp = Time.now.to_i
directory = File.join(File.dirname(__FILE__), 'db/migrate')
filename = File.join(directory, "#{timestamp}_#{name}.rb")
unless File.directory?(directory)
FileUtils.mkdir_p directory
end
File.open(filename, 'w') do |f|
f.puts content
end
puts "Created the migration #{filename}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment