-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile.rb
38 lines (32 loc) · 988 Bytes
/
Rakefile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'feed_entry'
require 'active_record'
require 'fileutils'
namespace :db do
desc "migrate your database"
task :migrate do
ActiveRecord::Migrator.migrate(
'db/migrate',
ENV["VERSION"] ? ENV["VERSION"].to_i : nil
)
end
desc "create an ActiveRecord migration in ./db/migrate"
task :create_migration do
name = ENV['NAME']
abort("no NAME specified. use `rake db:create_migration NAME=create_users`") if !name
migrations_dir = File.join("db", "migrate")
version = ENV["VERSION"] || Time.now.utc.strftime("%Y%m%d%H%M%S")
filename = "#{version}_#{name}.rb"
migration_name = name.gsub(/_(.)/) { $1.upcase }.gsub(/^(.)/) { $1.upcase }
FileUtils.mkdir_p(migrations_dir)
open(File.join(migrations_dir, filename), 'w') do |f|
f << (<<-EOS).gsub(" ", "")
class #{migration_name} < ActiveRecord::Migration
def self.up
end
def self.down
end
end
EOS
end
end
end