Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# 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', 'w') do |file|
AttachmentData.find_each.with_index do |attachment_data, index|
if index % 500 == 0
print '.'
file.puts attachment_data.file.url
file.puts attachment_data.file.url(:thumbnail) if attachment_data.file.url(:thumbnail)
puts ''
puts "File written to #{path}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment