#!/usr/bin/env ruby require File.expand_path('../../config/boot.rb', __FILE__) require File.expand_path('../../config/environment.rb', __FILE__) status = 0 done_anything = false if ARGV.length == 0 $stderr.puts "Missing arguments. Use '--help' for help message." status = 1 end for arg in ARGV case arg.to_s when '-h', '--help' puts <<-EOH SYNOPSIS refresh_enum [-h] [
...] DESCRIPTION Refreshes the enumerated column(s) from one or more listed tables. TABLES queries allowed models and flavors emails queued_email flavors (more to come) EOH when 'query', 'queries' ActiveRecord::Migration.change_column(:queries, :model, :enum, :limit => Query.all_models) ActiveRecord::Migration.change_column(:queries, :flavor, :enum, :limit => Query.all_flavors) done_anything = true when 'email', 'emails', 'queued_email', 'queued_emails' ActiveRecord::Migration.change_column(:queued_emails, :flavor, :enum, :limit => QueuedEmail.all_flavors) done_anything = true when 'jason' raise "nothing to do" done_anything = true else $stderr.puts "Unsupported or invalid table: '#{arg}'" status = 1 end end if done_anything require 'active_record/schema_dumper' File.open("#{RAILS_ROOT}/db/schema.rb", "w") do |file| ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file) end end exit status