16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/mongoid/lazy_migration/tasks.rb', line 16
def cleanup(model)
if model.in? Mongoid::LazyMigration.models_to_migrate
raise "Remove the migration from your model before cleaning up the database"
end
if model.where(:migration_state => :processing).limit(1).count > 0
raise ["Some models are still being processed.",
"Remove the migration code, and go inspect them with:",
"#{model}.where(:migration_state => :processing))",
"Don't forget to remove the migration block"].join("\n")
end
selector = { :migration_state => { "$exists" => true }}
changes = {"$unset" => { :migration_state => 1}}
safety = { :safe => true, :multi => true }
multi = { :multi => true }
if Mongoid::LazyMigration.mongoid3
model.with(safety).where(selector).query.update(changes, multi)
else
model.collection.update(selector, changes, safety.merge(multi))
end
end
|