Skip to content

Instantly share code, notes, and snippets.

@jcoyne
Created March 20, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcoyne/e56dd3226a1aa53b933fb10ad426c92e to your computer and use it in GitHub Desktop.
Save jcoyne/e56dd3226a1aa53b933fb10ad426c92e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# frozen_string_literal: true
# Usage:
# ./bin/set-active-version <pathToVersionCSV>
puts 'Loading environment...'
require File.expand_path('../config/environment', __dir__)
require 'csv'
conn = ActiveRecord::Base.connection
versions = CSV.read(ARGV[0]).to_h
versions.each do |druid, version|
next unless version # Don't import if it doesn't have a version
conn.execute("UPDATE workflow_steps SET active_version = true WHERE druid = '#{druid}' AND version='#{version}'")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment