-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
49 lines (45 loc) · 1.45 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
#!/usr/bin/env ruby
# -*- ruby -*-
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
desc "Run tests"
task :default => [ 'db:test:prepare', :spec ]
require_relative 'lib/environment'
db_namespace = namespace :db do
desc "Migrate the db"
task :migrate do
Environment.environment = 'development'
ActiveRecord::Migrator.migrate("db/migrate/")
db_namespace["schema:dump"].invoke
end
namespace :test do
desc "Prepare the test database"
task :prepare do
Environment.environment = 'test'
file = ENV['SCHEMA'] || "db/schema.rb"
if File.exists?(file)
load(file)
else
abort %{#{file} doesn't exist yet. Run `rake db:migrate` to create it.}
end
end
end
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
task :rollback do
Environment.environment = 'development'
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
db_namespace["schema:dump"].invoke
end
namespace :schema do
desc 'Create a db/schema.rb file that can be portably used against any DB supported by AR'
task :dump do
require 'active_record/schema_dumper'
Environment.environment = 'development'
filename = ENV['SCHEMA'] || "db/schema.rb"
File.open(filename, "w:utf-8") do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
end
end
end