Created
December 10, 2014 23:41
-
-
Save jwright/0420ba0adb163f6b4d89 to your computer and use it in GitHub Desktop.
Rake task to generate an empty Sequel migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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