Skip to content

Instantly share code, notes, and snippets.

@ismarsantos
Last active May 21, 2021 00:25
Show Gist options
  • Save ismarsantos/aa8084bc53010dab13fea31fbb741334 to your computer and use it in GitHub Desktop.
Save ismarsantos/aa8084bc53010dab13fea31fbb741334 to your computer and use it in GitHub Desktop.
Rails: example how to user change_column_null
# db/migrations/20190626011110_add_jti_to_users
class AddJtiToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :jti, :string
# populate jti so we can make it not nullable
User.all.each do |user|
user.update_column(:jti, SecureRandom.uuid)
end
change_column_null :users, :jti, false
add_index :users, :jti, unique: true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment