From be3fb85a04cecd3cf710b9922487b4a3eab2f2e0 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Mon, 20 May 2019 14:18:28 +0530 Subject: [PATCH] DEV: add post migration checks and raise error if failed. --- lib/tasks/uploads.rake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake index cc0846b59d4..a507f70fb77 100644 --- a/lib/tasks/uploads.rake +++ b/lib/tasks/uploads.rake @@ -348,9 +348,12 @@ def migrate_to_s3 puts + failure_message = "S3 migration failed for db '#{db}'." + if failed.size > 0 puts "Failed to upload #{failed.size} files" puts failed.join("\n") + raise failure_message elsif s3_objects.size + synced >= local_files.size puts "Updating the URLs in the database..." @@ -437,6 +440,18 @@ def migrate_to_s3 end end + base_url = File.join(SiteSetting.Upload.s3_base_url, prefix) + count = Upload.where("url NOT LIKE '#{base_url}%'").count + raise "#{count} of #{Upload.count} uploads are not migrated to S3. #{failure_message}" if count > 0 + + cdn_path = SiteSetting.cdn_path("/uploads/#{db}").sub(/https?:/, "") + count = Post.where("cooked LIKE '%#{cdn_path}%'").count + raise "#{count} posts are not remapped to new S3 upload URL. #{failure_message}" if count > 0 + + Rake::Task['posts:missing_uploads'].invoke + count = PostCustomField.where(name: Post::MISSING_UPLOADS).count + raise failure_message if count > 0 + puts "Done!" end