-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
45 lines (37 loc) · 1.14 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
require_relative 'config/application'
namespace :db do
desc 'create the database'
task :create do
puts "Creating #{db_path}..."
touch db_path
end
desc 'drop the database'
task :drop do
puts "Deleting #{db_path}..."
rm_f db_path
end
desc 'migrate the database (options: VERSION=x).'
task :migrate do
ActiveRecord::Migrator.migrations_paths << File.dirname(__FILE__) + 'db/migrate'
ActiveRecord::Migration.verbose = true
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, version)
end
desc 'Retrieves the current schema version number'
task :version do
puts "Current version: #{ActiveRecord::Migrator.current_version}"
end
desc 'populate the database with sample data'
task :seed do
Dir["#{__dir__}/app/models/*.rb"].each { |file| require file }
require "#{__dir__}/db/seeds.rb"
end
desc 'Gives you a timestamp for your migration file name'
task :timestamp do
puts DateTime.now.strftime('%Y%m%d%H%M%S')
end
private
def db_path
ActiveRecord::Base.configurations["development"]["database"]
end
end