From 0f4288d91de7b48f7bbed832ca80246b0055cc64 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 9 Aug 2026 16:03:40 +0200 Subject: Drop nodes.external_url The column moved to page.rb and was now written only by publish_draft! and by the chapter seed, and read by nothing. lib/tasks/pages.rake goes with it. backfill_external_url reads the dropped column. backfill_address is spent and no longer safe to re-run. --- lib/tasks/pages.rake | 61 ---------------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 lib/tasks/pages.rake (limited to 'lib') diff --git a/lib/tasks/pages.rake b/lib/tasks/pages.rake deleted file mode 100644 index ea0776b7..00000000 --- a/lib/tasks/pages.rake +++ /dev/null @@ -1,61 +0,0 @@ -namespace :pages do - desc "Backfill pages.slug and pages.parent_node_id from each page's " \ - "node. Historical accuracy is not attempted. Every revision gets " \ - "the node's current address, which is right for head and draft and " \ - "harmless for older revisions, and avoids nil checks everywhere. " \ - "Dry run unless WRITE=1." - task :backfill_address => :environment do - write = ENV["WRITE"] == "1" - puts "DRY RUN -- nothing written. Re-run with WRITE=1." unless write - - touched = 0 - Node.find_each do |node| - scope = node.pages.where("slug IS DISTINCT FROM :s OR parent_node_id IS DISTINCT FROM :p", - :s => node.slug, :p => node.parent_id) - count = scope.count - next if count.zero? - - scope.update_all(:slug => node.slug, :parent_node_id => node.parent_id) if write - touched += count - end - - # Autosaves carry no node_id -- has_many :pages does not cover them. - Node.where.not(:autosave_id => nil).includes(:autosave).find_each do |node| - a = node.autosave - next if a.slug == node.slug && a.parent_node_id == node.parent_id - - a.update_columns(:slug => node.slug, :parent_node_id => node.parent_id) if write - touched += 1 - end - - puts "#{write ? "updated" : "would update"} #{touched} pages" - end - - desc "Backfill pages.external_url from each page's node." - task :backfill_external_url => :environment do - write = ENV["WRITE"] == "1" - puts "DRY RUN -- nothing written. Re-run with WRITE=1." unless write - - touched = 0 - Node.where.not(:external_url => [nil, ""]).find_each do |node| - scope = node.pages.where("external_url IS DISTINCT FROM :u", :u => node.external_url) - count = scope.count - next if count.zero? - - scope.update_all(:external_url => node.external_url) if write - touched += count - end - - # Autosaves carry no node_id, so has_many :pages does not cover them. - Node.where.not(:autosave_id => nil).where.not(:external_url => [nil, ""]) - .includes(:autosave).find_each do |node| - a = node.autosave - next if a.nil? || a.external_url == node.external_url - - a.update_columns(:external_url => node.external_url) if write - touched += 1 - end - - puts "#{write ? "updated" : "would update"} #{touched} pages" - end -end -- cgit v1.3