-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
64 lines (49 loc) · 1.76 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
require 'rake'
require 'rspec/core/rake_task'
require_relative 'config/application'
desc "create the database"
task "db:create" do
puts "Creating file #{DB_PATH} if it doesn't exist..."
touch DB_PATH
end
desc "drop the database"
task "db:drop" do
puts "Deleting #{DB_PATH}..."
rm_f DB_PATH
end
desc "migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
task "db:migrate" do
ActiveRecord::Migrator.migrations_paths << File.dirname(__FILE__) + 'db/migrate'
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration|
ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
end
end
desc "populate the test database with sample data"
task "db:seed" do
require APP_ROOT.join('db', 'seeds.rb')
end
desc 'Retrieves the current schema version number'
task "db:version" do
puts "Current version: #{ActiveRecord::Migrator.current_version}"
end
desc 'Start IRB with application environment loaded'
task "console" do
exec "irb -r./config/application"
end
desc "Run the specs"
RSpec::Core::RakeTask.new(:spec)
task :default => :specs
desc 'generate migration file skeleton'
task 'generate:migration' do
migration_name = ARGV.last
camelized_migration_name = migration_name.split('_').map {|w| w.capitalize}.join
directory = File.dirname(__FILE__) + '/db/migrate/'
filepath = "#{directory + Time.now.strftime('%Y%m%d%H%M%S')}_#{migration_name}.rb"
filecontents =
"class #{camelized_migration_name} < ActiveRecord::Migration\n" +
" # this is for you to implement :)\n" +
"end"
File.open(filepath, 'w') { |file| file.write(filecontents) }
task ARGV.last.to_sym do ; end
end