Skip to content

Instantly share code, notes, and snippets.

@rbq
Created April 30, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbq/d1e1010971c24dfc0b0dc965c30cde4c to your computer and use it in GitHub Desktop.
Save rbq/d1e1010971c24dfc0b0dc965c30cde4c to your computer and use it in GitHub Desktop.
Rails 6 migrations to upgrade SQLite booleans from t/f to 1/0
class ConvertSqliteBooleans < ActiveRecord::Migration[6.0]
BOOLEANS = [
[ 'table_name', 'column_name' ],
[ 'table_name', 'column_name' ],
]
def up
BOOLEANS.each do |table, column|
execute "UPDATE #{table} SET #{column} = 1 WHERE #{column} = 't';"
execute "UPDATE #{table} SET #{column} = 0 WHERE #{column} = 'f' OR #{column} IS NULL;"
end
end
def down
BOOLEANS.each do |table, column|
execute "UPDATE #{table} SET #{column} = 't' WHERE #{column} = 1;"
execute "UPDATE #{table} SET #{column} = 'f' WHERE #{column} = 0;"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment