Created
August 10, 2020 13:10
-
-
Save billguy/936e09a629ed73674f30b1dd01909878 to your computer and use it in GitHub Desktop.
Replace sqlite t & f boolean fields with 1 & 0 in one shot. Fixes config.active_record.sqlite3.represent_boolean_as_integer for older db's.
This file contains hidden or 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
Rails.application.eager_load! | |
ApplicationRecord.descendants.each do |klass| | |
klass.columns.select{ |c| c.type == :boolean }.map(&:name).each do |bool_column| | |
klass.where("#{bool_column} = 't'").update_all(bool_column.to_sym => 1) | |
klass.where("#{bool_column} = 'f'").update_all(bool_column.to_sym => 0) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment