Skip to content

Instantly share code, notes, and snippets.

@jonathanmeaney
Last active July 27, 2020 19:23
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 jonathanmeaney/4cf29f4ade53760c969fa564331567e4 to your computer and use it in GitHub Desktop.
Save jonathanmeaney/4cf29f4ade53760c969fa564331567e4 to your computer and use it in GitHub Desktop.
Iterate a list of table names and generate a migration file to add the lock_version column to each
[].each do |table|
time = Time.now.strftime("%Y%m%d%H%M%S")
filename = "#{time}_add_lock_version_to_#{table}.rb"
File.open(filename, 'w') do |file|
file.puts("class AddLockVersionTo#{table.camelize} < ActiveRecord::Migration[5.2]")
file.puts(" def change")
file.puts(" add_column :#{table}, :lock_version, :integer, default: 0")
file.puts(" end")
file.puts("end")
end
sleep(1.second)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment