praaveen
Published in

praaveen

bulk file update in ruby

Rails Migration files update by regular expression

We recently upgrade from rails 4 to rails 5 and while running rspec migration need to update all migration file by adding [5.0]

From “ActiveRecord::Migration”

To “ActiveRecord::Migration[5.0]”

We have around 400 files and changing manually is hard. So small script with regular expression to replace “ActiveRecord::Migration” to “ActiveRecord::Migration[5.0]”

`To “ActiveRecord::Migration[5.0]”

Dir.glob("#{Rails.root}/db/migrate/*").each do |file_name|text = File.read(file_name)File.open(file_name, "w") {|file| file << text.gsub(/\bActiveRecord::Migration\b/,"ActiveRecord::Migration[5.0]") }end

Technical blog

Recommended from Medium

Setup Black and Isort in VSCode

What Is TWINUI & How to Remove It from Default Apps

5 Reasons Why I Love Tech Guys

Algorithm Tool Kit: Arrays

Data classes in Kotlin: how do they impact an application size

Firebase Hosting for Flutter Web Projects in 4 easy steps

CLI application — Wikipedia

Algo: Binary-Search — Java

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Praaveen Vr

Praaveen Vr

Ruby on Rails Freelancer

More from Medium

My journey becoming a Unity game developer: Make a game look beautiful-Door, Frame, and Wall…

Compiling imagemagick with HEIC support in heroku(ubuntu)

What are Unity Skyboxes?