From 57f74d8da4f4906fde07caa6cb05cbb824edcbc4 Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Mon, 7 Sep 2020 19:05:37 -0500 Subject: [Database, Models] Add indexes to users.username and User.find_by_lower_username utility methods --- db/migrate/20200907195410_add_index_to_users_username.rb | 8 ++++++++ db/schema.rb | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20200907195410_add_index_to_users_username.rb (limited to 'db') diff --git a/db/migrate/20200907195410_add_index_to_users_username.rb b/db/migrate/20200907195410_add_index_to_users_username.rb new file mode 100644 index 000000000..06452e0dd --- /dev/null +++ b/db/migrate/20200907195410_add_index_to_users_username.rb @@ -0,0 +1,8 @@ +class AddIndexToUsersUsername < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def change + add_index :users, :username, unique: true, algorithm: :concurrently + add_index :users, 'lower(username)', unique: true, algorithm: :concurrently, name: 'index_on_users_username_lowercase' + end +end diff --git a/db/schema.rb b/db/schema.rb index 87cca4ea1..fbcf8e636 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: 2020_09_04_201028) do +ActiveRecord::Schema.define(version: 2020_09_07_195410) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -990,12 +990,14 @@ ActiveRecord::Schema.define(version: 2020_09_04_201028) do t.string "username" t.string "kobold" t.string "webauthn_id" + t.index "lower((username)::text)", name: "index_on_users_username_lowercase", unique: true t.index ["account_id"], name: "index_users_on_account_id" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id" t.index ["email"], name: "index_users_on_email", unique: true t.index ["remember_token"], name: "index_users_on_remember_token", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + t.index ["username"], name: "index_users_on_username", unique: true end create_table "web_push_subscriptions", force: :cascade do |t| -- cgit