Last active
July 27, 2020 19:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[].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