forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_nuke.rake
More file actions
41 lines (40 loc) · 1.56 KB
/
Copy pathdb_nuke.rake
File metadata and controls
41 lines (40 loc) · 1.56 KB
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
namespace :db do
task :nuke => :environment do
# this causes any scribd_docs associated with attachments to be deleted from scribd.
# that way we are polite and good citizens so to scribd.com
#
# dont kill db:nuke if it dies with destoying all the attachments.
# it probably is just because it tries to delete an attachment who's
# file on disk or s3 is no longer there.
Attachment.destroy_all rescue nil
abcs = ActiveRecord::Base.configurations
["development"].each do |db|
case abcs[db]["adapter"]
when 'mysql', 'mysql2'
ActiveRecord::Base.establish_connection(db.to_sym)
conn = ActiveRecord::Base.connection
conn.execute("DROP DATABASE #{abcs[db]["database"]}")
conn.execute("CREATE DATABASE #{abcs[db]["database"]}")
ActiveRecord::Base.establish_connection(db.to_sym)
when "sqlite", "sqlite3"
dbfile = abcs[db]["database"] || abcs[db]["dbfile"]
begin
File.delete(dbfile) if File.exist?(dbfile)
rescue
f = File.open(dbfile, "w")
f.write("")
f.close
end
ActiveRecord::Base.establish_connection(db.to_sym)
else
raise "Task not supported by '#{abcs[db]["adapter"]}'"
end
ENV['RAILS_ENV'] = db
Rake::Task["db:migrate"].dup.invoke
Rake::Task["db:load_initial_data"].dup.invoke
# Rake::Task["db:fixtures:load"].dup.invoke
Rake::Task["db:test:prepare"].dup.invoke
# Rake::Task["annotate_models"].dup.invoke
end
end
end