-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
executable file
·79 lines (64 loc) · 1.83 KB
/
Rakefile
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require File.expand_path('../config/environment', __FILE__)
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require 'rspec/core'
require 'rspec/core/rake_task'
task :rails_env do
end
task :environment do
ENV["RACK_ENV"] ||= 'development'
require File.expand_path("../config/environment", __FILE__)
end
module Rails
def self.application
Struct.new(:config, :paths) do
def load_seed
require File.expand_path('../application', __FILE__)
require File.expand_path('../db/seeds', __FILE__)
end
end.new(config, paths)
end
def self.config
require 'erb'
db_config = YAML.load(ERB.new(File.read("config/database.yml")).result)
Struct.new(:database_configuration).new(db_config)
end
def self.paths
{ 'db/migrate' => ["#{root}/db/migrate"] }
end
def self.env
env = ENV['RACK_ENV'] || "development"
ActiveSupport::StringInquirer.new(env)
end
def self.root
File.dirname(__FILE__)
end
end
namespace :db do
desc "Generate migration. Specify name in the NAME variable"
task :create_migration => :environment do
name = ENV['NAME'] || raise("Specify name: rake db:create_migration NAME=create_users")
timestamp = Time.now.strftime("%Y%m%d%H%M%S")
path = File.expand_path("../db/migrate/#{timestamp}_#{name}.rb", __FILE__)
migration_class = name.split("_").map(&:capitalize).join
File.open(path, 'w') do |file|
file.write <<-EOF.strip_heredoc
class #{migration_class} < ActiveRecord::Migration
def self.up
end
def self.down
end
end
EOF
end
puts "DONE"
puts path
end
end
Rake.load_rakefile "active_record/railties/databases.rake"