Skip to content

Commit d2a9bfc

Browse files
committed
Add not null constraint to email and crypted password
1 parent c82c0bb commit d2a9bfc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class AddNotNullConstraintsToParticipants < ActiveRecord::Migration[7.1]
2+
def change
3+
# update any existing NULL values, just in case
4+
Participant.where(email: nil).update_all(email: 'INVALID')
5+
Participant.where(crypted_password: nil).update_all(crypted_password: 'INVALID')
6+
7+
change_column_null :participants, :email, false
8+
change_column_null :participants, :crypted_password, false
9+
end
10+
11+
def down
12+
change_column_null :participants, :email, true
13+
change_column_null :participants, :crypted_password, true
14+
end
15+
end

db/schema.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.1].define(version: 2025_03_09_183552) do
13+
ActiveRecord::Schema[7.1].define(version: 2025_03_13_020004) do
1414
create_schema "heroku_ext"
1515

1616
# These are extensions that must be enabled in order to support this database
@@ -69,11 +69,11 @@
6969

7070
create_table "participants", id: :serial, force: :cascade do |t|
7171
t.string "name", limit: 255
72-
t.string "email", limit: 255
72+
t.string "email", limit: 255, null: false
7373
t.text "bio"
7474
t.datetime "created_at", precision: nil, null: false
7575
t.datetime "updated_at", precision: nil, null: false
76-
t.string "crypted_password", limit: 255
76+
t.string "crypted_password", limit: 255, null: false
7777
t.string "persistence_token", limit: 255
7878
t.string "perishable_token", limit: 255, default: "", null: false
7979
t.datetime "email_confirmed_at", precision: nil

0 commit comments

Comments
 (0)