同事对email和name添加索引

This commit is contained in:
huang 2018-01-30 14:41:24 +08:00
parent 7af0b50327
commit bc8179fc2d
10 changed files with 215 additions and 99 deletions

View File

@ -28,44 +28,52 @@
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="users_controller.rb" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/controllers/users_controller.rb">
<file leaf-file-name="sessions_controller.rb" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/controllers/sessions_controller.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-6.611111">
<caret line="14" column="29" selection-start-line="14" selection-start-column="29" selection-end-line="14" selection-end-column="29" />
<state vertical-scroll-proportion="0.0">
<caret line="12" column="0" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="production.rb" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/config/environments/production.rb">
<file leaf-file-name="user.rb" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/models/user.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.35588634">
<caret line="45" column="0" selection-start-line="45" selection-start-column="0" selection-end-line="45" selection-end-column="0" />
<state vertical-scroll-proportion="0.0">
<caret line="4" column="28" selection-start-line="4" selection-start-column="20" selection-end-line="4" selection-end-column="28" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="_error_messages.html.erb" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/views/flash/_error_messages.html.erb">
<file leaf-file-name="20180125150438_add_index_to_users_email.rb" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/db/migrate/20180125150438_add_index_to_users_email.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-7.1923075">
<caret line="11" column="9" selection-start-line="11" selection-start-column="9" selection-end-line="11" selection-end-column="9" />
<state vertical-scroll-proportion="0.0">
<caret line="1" column="12" selection-start-line="1" selection-start-column="12" selection-end-line="1" selection-end-column="12" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="application.html.erb" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/views/layouts/application.html.erb">
<file leaf-file-name="schema.rb" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/db/schema.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-13.076923">
<caret line="20" column="9" selection-start-line="20" selection-start-column="9" selection-end-line="20" selection-end-column="9" />
<folding>
<marker date="1517229246343" expanded="true" signature="493:505" placeholder="..." />
</folding>
<state vertical-scroll-proportion="0.48258063">
<caret line="22" column="2" selection-start-line="22" selection-start-column="2" selection-end-line="22" selection-end-column="2" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="schema_statements.rb" pinned="false" current-in-tab="false">
<entry file="file://$USER_HOME$/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/schema_statements.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="498" column="69" selection-start-line="498" selection-start-column="10" selection-end-line="498" selection-end-column="69" />
<folding />
</state>
</provider>
</entry>
@ -88,7 +96,6 @@
<option value="$PROJECT_DIR$/app/assets/stylesheets/application.css.scss" />
<option value="$PROJECT_DIR$/test/test_helper.rb" />
<option value="$PROJECT_DIR$/test/models/user_test.rb" />
<option value="$PROJECT_DIR$/db/migrate/20180125150438_add_index_to_users_email.rb" />
<option value="$PROJECT_DIR$/test/fixtures/users.yml" />
<option value="$PROJECT_DIR$/test/integration/site_layout_test.rb" />
<option value="$PROJECT_DIR$/app/views/layouts/_header.html.erb" />
@ -96,13 +103,17 @@
<option value="$PROJECT_DIR$/app/models/user.rb" />
<option value="$PROJECT_DIR$/app/assets/stylesheets/custom.css.scss" />
<option value="$PROJECT_DIR$/Gemfile" />
<option value="$PROJECT_DIR$/config/routes.rb" />
<option value="$PROJECT_DIR$/app/views/users/show.html.erb" />
<option value="$PROJECT_DIR$/app/views/users/new.html.erb" />
<option value="$PROJECT_DIR$/app/views/flash/_error_message.html.erb" />
<option value="$PROJECT_DIR$/app/controllers/users_controller.rb" />
<option value="$PROJECT_DIR$/app/views/layouts/application.html.erb" />
<option value="$PROJECT_DIR$/config/environments/production.rb" />
<option value="$PROJECT_DIR$/app/views/sessions/new.html.erb" />
<option value="$PROJECT_DIR$/config/routes.rb" />
<option value="$PROJECT_DIR$/app/controllers/sessions_controller.rb" />
<option value="$PROJECT_DIR$/db/migrate/20180125150438_add_index_to_users_email.rb" />
<option value="$PROJECT_DIR$/db/schema.rb" />
</list>
</option>
</component>
@ -178,7 +189,25 @@
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="config" />
<option name="myItemId" value="db" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="uask" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="uask" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="db" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="migrate" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
@ -195,8 +224,44 @@
<option name="myItemId" value="config" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="environments" />
<option name="myItemId" value="uask" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="uask" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="app" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="views" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="uask" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="uask" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="app" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="views" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="sessions" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
@ -471,40 +536,6 @@
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/app/models/user.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="7" column="21" selection-start-line="7" selection-start-column="2" selection-end-line="7" selection-end-column="21" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/helpers/application_helper.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="1" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="1" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/views/layouts/application.html.erb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="19" column="35" selection-start-line="19" selection-start-column="32" selection-end-line="19" selection-end-column="38" />
<folding>
<marker date="1517229246343" expanded="true" signature="493:505" placeholder="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/views/layouts/_header.html.erb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="32" column="31" selection-start-line="32" selection-start-column="31" selection-end-line="32" selection-end-column="31" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/views/layouts/_footer.html.erb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
@ -658,13 +689,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/controllers/welcomes_controller.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="7" column="0" selection-start-line="7" selection-start-column="0" selection-end-line="7" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/Guardfile">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
@ -686,13 +710,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/db/migrate/20180125150438_add_index_to_users_email.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.19318181">
<caret line="5" column="0" selection-start-line="5" selection-start-column="0" selection-end-line="5" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/models/user_test.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.425">
@ -783,14 +800,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/models/user.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.49707603">
<caret line="10" column="0" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/Gemfile">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="1.5">
@ -799,14 +808,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/routes.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="3" column="18" selection-start-line="3" selection-start-column="18" selection-end-line="3" selection-end-column="18" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/views/users/show.html.erb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
@ -828,7 +829,7 @@
<state vertical-scroll-proportion="-13.076923">
<caret line="20" column="9" selection-start-line="20" selection-start-column="9" selection-end-line="20" selection-end-column="9" />
<folding>
<marker date="1517229246343" expanded="true" signature="493:505" placeholder="..." />
<marker date="1517229246343" expanded="true" signature="-1:-1" placeholder="..." />
</folding>
</state>
</provider>
@ -841,6 +842,14 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/environments/production.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-7.3055553">
<caret line="45" column="0" selection-start-line="45" selection-start-column="0" selection-end-line="45" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/controllers/users_controller.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-6.611111">
@ -849,10 +858,66 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/environments/production.rb">
<entry file="file://$PROJECT_DIR$/app/views/sessions/new.html.erb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.35588634">
<caret line="45" column="0" selection-start-line="45" selection-start-column="0" selection-end-line="45" selection-end-column="0" />
<state vertical-scroll-proportion="-12.423077">
<caret line="19" column="6" selection-start-line="19" selection-start-column="6" selection-end-line="19" selection-end-column="6" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/controllers/welcomes_controller.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.15354839">
<caret line="7" column="0" selection-start-line="7" selection-start-column="0" selection-end-line="7" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/routes.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="6" column="39" selection-start-line="6" selection-start-column="38" selection-end-line="6" selection-end-column="39" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/controllers/sessions_controller.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="12" column="0" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/models/user.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="4" column="28" selection-start-line="4" selection-start-column="20" selection-end-line="4" selection-end-column="28" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/schema_statements.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="498" column="69" selection-start-line="498" selection-start-column="10" selection-end-line="498" selection-end-column="69" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/db/migrate/20180125150438_add_index_to_users_email.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="1" column="12" selection-start-line="1" selection-start-column="12" selection-end-line="1" selection-end-column="12" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/db/schema.rb">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.48258063">
<caret line="22" column="2" selection-start-line="22" selection-start-column="2" selection-end-line="22" selection-end-column="2" />
<folding />
</state>
</provider>

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the Sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,12 @@
class SessionsController < ApplicationController
def new
end
def create
render :new
end
def destroy
end
end

View File

@ -0,0 +1,2 @@
module SessionsHelper
end

View File

@ -0,0 +1,20 @@
<h1>Sessions#new</h1>
<p>Find me in app/views/sessions/new.html.erb</p>
<h1>Log in</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(:session, url: login_path) do |f| %>
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
<%= f.submit "Log in", class: "btn btn-primary" %>
<% end %>
<p>New user? <%= link_to "Sign up now!", signup_path %></p>
</div>
</div>

View File

@ -1,11 +1,13 @@
Rails.application.routes.draw do
resource :users
# get 'users/new', :as => "signup"
resources :users
root 'welcomes#home', :as => "home"
get 'sessions/new'
get 'help' => "welcomes#help"
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
get "help" => "welcomes#help"
resource :users
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

View File

@ -1,5 +1,5 @@
class AddIndexToUsersEmail < ActiveRecord::Migration
def change
add_index :users, :email, unique: true
add_index(:users, [:email, :name], unique: true)
end
end

View File

@ -20,7 +20,7 @@ ActiveRecord::Schema.define(version: 20180125150438) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["email", "name"], name: "index_users_on_email", unique: true, using: :btree
end

View File

@ -0,0 +1,9 @@
require 'test_helper'
class SessionsControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end