-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
52 lines (48 loc) · 1.43 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
#!/usr/bin/env ruby
# -*- ruby -*-
require_relative 'bootstrap_ar'
require 'yaml'
require 'rake/testtask'
Rake::TestTask.new( test: "db:test:prepare") do |t|
t.pattern = "test/**/test_*.rb"
end
desc "Run tests"
task :default => :test
db_namespace = namespace :db do
desc "Migrate the db"
task :migrate do
connect_to 'development'
ActiveRecord::Migrator.migrate("db/migrate/")
db_namespace["schema:dump"].invoke
end
namespace :test do
desc "Prepare the test database"
task :prepare do
connect_to '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
connect_to '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'
connect_to '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