* Move emails from users table to email_addresses table. * Validate that addresses are formatted correctly and are unique across users. Existing invalid emails are grandfathered in. * Add is_verified flag (the address has been confirmed by the user). * Add is_deliverable flag (an undeliverable address is an address that bounces). * Normalize addresses to prevent registering multiple accounts with the same email address (using tricks like Gmail's plus addressing).
21 lines
737 B
Ruby
21 lines
737 B
Ruby
class CreateEmailAddresses < ActiveRecord::Migration[6.0]
|
|
def change
|
|
create_table :email_addresses do |t|
|
|
t.timestamps
|
|
|
|
t.references :user, index: false, null: false
|
|
t.string :address, null: false
|
|
t.string :normalized_address, null: false
|
|
t.boolean :is_verified, default: false, null: false
|
|
t.boolean :is_deliverable, default: true, null: false
|
|
|
|
t.index :address
|
|
t.index :normalized_address
|
|
t.index :user_id, unique: true
|
|
|
|
t.index :address, name: "index_email_addresses_on_address_trgm", using: :gin, opclass: :gin_trgm_ops
|
|
t.index :normalized_address, name: "index_email_addresses_on_normalized_address_trgm", using: :gin, opclass: :gin_trgm_ops
|
|
end
|
|
end
|
|
end
|