Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save billguy/936e09a629ed73674f30b1dd01909878 to your computer and use it in GitHub Desktop.
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.
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