forked from mongodb/mongoid
/
database.rake
89 lines (74 loc) · 2.27 KB
/
database.rake
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
namespace :db do
unless Rake::Task.task_defined?("db:drop")
desc "Drops all the collections for the database for the current Rails.env"
task :drop => "mongoid:drop"
end
unless Rake::Task.task_defined?("db:purge")
desc "Drop all collections except the system collections"
task :purge => "mongoid:purge"
end
unless Rake::Task.task_defined?("db:seed")
# if another ORM has defined db:seed, don"t run it twice.
desc "Load the seed data from db/seeds.rb"
task :seed => :environment do
seed_file = File.join(Rails.root, "db", "seeds.rb")
load(seed_file) if File.exist?(seed_file)
end
end
unless Rake::Task.task_defined?("db:setup")
desc "Create the database, and initialize with the seed data"
task :setup => [ "db:create", "db:mongoid:create_indexes", "db:seed" ]
end
unless Rake::Task.task_defined?("db:reseed")
desc "Delete data and seed"
task :reseed => [ "db:drop", "db:seed" ]
end
unless Rake::Task.task_defined?("db:create")
task :create => :environment do
# noop
end
end
unless Rake::Task.task_defined?("db:migrate")
task :migrate => :environment do
# noop
end
end
unless Rake::Task.task_defined?("db:schema:load")
namespace :schema do
task :load do
# noop
end
end
end
unless Rake::Task.task_defined?("db:test:prepare")
namespace :test do
task :prepare do
# noop
end
end
end
unless Rake::Task.task_defined?("db:create_indexes")
task :create_indexes => "mongoid:create_indexes"
end
unless Rake::Task.task_defined?("db:remove_indexes")
task :remove_indexes => "mongoid:remove_indexes"
end
namespace :mongoid do
desc "Create the indexes defined on your mongoid models"
task :create_indexes => :environment do
::Rails::Mongoid.create_indexes
end
desc "Remove the indexes defined on your mongoid models without questions!"
task :remove_indexes => :environment do
::Rails::Mongoid.remove_indexes
end
desc "Drops the database for the current Rails.env"
task :drop => :environment do
::Mongoid::Sessions.default.drop
end
desc "Drop all collections except the system collections"
task :purge => :environment do
::Mongoid.purge!
end
end
end