From 20150659e6f084d6c6fb4080d08c4104b8ac0570 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Wed, 15 Nov 2017 04:37:17 +0900 Subject: Add uniqueness to block email domains (#5692) --- .../20171114080328_add_index_domain_to_email_domain_blocks.rb | 8 ++++++++ db/schema.rb | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20171114080328_add_index_domain_to_email_domain_blocks.rb (limited to 'db') diff --git a/db/migrate/20171114080328_add_index_domain_to_email_domain_blocks.rb b/db/migrate/20171114080328_add_index_domain_to_email_domain_blocks.rb new file mode 100644 index 000000000..84a341510 --- /dev/null +++ b/db/migrate/20171114080328_add_index_domain_to_email_domain_blocks.rb @@ -0,0 +1,8 @@ +class AddIndexDomainToEmailDomainBlocks < ActiveRecord::Migration[5.1] + disable_ddl_transaction! + + def change + add_index :email_domain_blocks, :domain, algorithm: :concurrently, unique: true + change_column_default :email_domain_blocks, :domain, from: nil, to: '' + end +end diff --git a/db/schema.rb b/db/schema.rb index f16b24fd6..bf319ce55 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171109012327) do +ActiveRecord::Schema.define(version: 20171114080328) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -126,9 +126,10 @@ ActiveRecord::Schema.define(version: 20171109012327) do end create_table "email_domain_blocks", force: :cascade do |t| - t.string "domain", null: false + t.string "domain", default: "", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["domain"], name: "index_email_domain_blocks_on_domain", unique: true end create_table "favourites", force: :cascade do |t| -- cgit