summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/init.rake22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/tasks/init.rake b/lib/tasks/init.rake
index adfaddfd..bf7bfa6b 100644
--- a/lib/tasks/init.rake
+++ b/lib/tasks/init.rake
@@ -78,6 +78,28 @@ namespace :cccms do
78 end 78 end
79end 79end
80 80
81namespace :pages do
82 desc "Populate search_vector for rows that have none. The trigger " \
83 "maintains it from then on, but fires only on insert or update, " \
84 "so rows that predate it -- a restore from a dump taken before " \
85 "the trigger existed, or a seed run against a database whose " \
86 "trigger had been dropped -- stay unsearchable until this runs."
87 task :backfill_search_vector => :environment do
88 Page.ensure_search_vector_trigger!
89 count = ActiveRecord::Base.connection.update(<<~SQL)
90 UPDATE page_translations
91 SET search_vector = to_tsvector(
92 'simple',
93 coalesce(title, '') || ' ' ||
94 coalesce(abstract, '') || ' ' ||
95 coalesce(body, '')
96 )
97 WHERE search_vector IS NULL
98 SQL
99 puts "populated #{count} translations"
100 end
101end
102
81Rake::Task["db:schema:load"].enhance do 103Rake::Task["db:schema:load"].enhance do
82 Page.ensure_search_vector_trigger! 104 Page.ensure_search_vector_trigger!
83end 105end