Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Created March 16, 2018 12:14
Show Gist options
  • Save chrisroos/7f728a0668289b6473d939acfc74a92d to your computer and use it in GitHub Desktop.
Save chrisroos/7f728a0668289b6473d939acfc74a92d to your computer and use it in GitHub Desktop.
# Script used to save the URL paths of all the AttachmentData records in the Whitehall database
#
# To use:
#
# 1. SSH to a whitehall_backend box in integration/staging
# 2. Save the script as /tmp/save-attachment-data-urls.rb
# 3. Run `sudo su - deploy`
# 4. Run `cd /var/apps/whitehall`
# 5. Run `govuk_setenv whitehall bundle exec rails r /tmp/save-attachment-data-urls.rb`
path = '/tmp/attachment-data-urls.txt'
File.open(path, 'w') do |file|
AttachmentData.find_each.with_index do |attachment_data, index|
if index % 500 == 0
print '.'
end
file.puts attachment_data.file.url
file.puts attachment_data.file.url(:thumbnail) if attachment_data.file.url(:thumbnail)
end
end
puts ''
puts "File written to #{path}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment