Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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