Skip to content

Commit 9ba7eac

Browse files
feat: add database default and NOT NULL guidance to migration template
1 parent bd370e2 commit 9ba7eac

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/generators/devise/webauthn/webauthn_id/templates/add_webauthn_id.rb.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ class AddWebauthnIdTo<%= user_table_name.camelize %> < ActiveRecord::Migration[<
2323
["UPDATE <%= user_table_name %> SET webauthn_id = ? WHERE id = ?", webauthn_id, row["id"]]
2424
))
2525
end
26+
# Note: if your application creates records using methods that skip
27+
# callbacks (e.g., insert_all), consider adding a database default
28+
# to ensure webauthn_id is always set. For example, in PostgreSQL:
29+
#
30+
# change_column_default :<%= user_table_name %>, :webauthn_id, from: nil, to: -> { "encode(gen_random_bytes(64), 'base64')" }
31+
#
32+
# For the same reason, you may want to add a NOT NULL constraint in a
33+
# separate migration after the backfill is complete:
34+
#
35+
# change_column_null :<%= user_table_name %>, :webauthn_id, false
2636
end
2737

2838
def down

0 commit comments

Comments
 (0)