-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
61 lines (51 loc) · 1.61 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
require "active_record"
require 'yaml'
require 'bundler/setup'
require "rake/testtask"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db = db_config[(ENV['RAILS_ENV'] || 'development')].merge({ schema_search_path: 'public' })
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db.except('database'))
ActiveRecord::Base.connection.create_database(db['database'])
puts "Database created."
end
desc "Migrate the database"
task :migrate do
ActiveRecord::Base.establish_connection(db)
ActiveRecord::Migrator.migrate("db/migrate/")
Rake::Task["db:schema"].invoke
puts "Database migrated."
end
desc "Drop the database"
task :drop do
ActiveRecord::Base.establish_connection(db)
ActiveRecord::Base.connection.drop_database(db["database"])
puts "Database deleted."
end
desc "Reset the database"
task :reset => [:drop, :create, :migrate]
namespace :schema do
desc "Set up the database"
task :load do
ActiveRecord::Base.establish_connection(db)
load 'db/schema.rb'
puts "Schema is applied."
end
desc 'Create a db/schema.rb file that is portable against any DB supported by AR'
task :dump do
ActiveRecord::Base.establish_connection(db)
require 'active_record/schema_dumper'
filename = "db/schema.rb"
File.open(filename, "w:utf-8") do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
end
end
end
Rake::TestTask.new do |t|
t.name = "test"
t.warning = false
t.test_files = FileList["test/**/*test.rb"]
end