Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add question order and foreign key indexes

  • Loading branch information...
commit 1472a2f3ddb8bddb4ddcb0aea79f89690abd705d 1 parent a2ff36a
Louis-Alban KIM lakim authored
2  app/models/survey.rb
View
@@ -3,7 +3,7 @@ class Survey < ActiveRecord::Base
has_many :sections, :dependent => :destroy, :inverse_of => :survey, :order => "position ASC"
accepts_nested_attributes_for :sections, :allow_destroy => true, :reject_if => lambda { |me| me[:title].blank? }
has_many :calls, :dependent => :destroy
- has_many :questions, :through => :sections
+ has_many :questions, :through => :sections, :order => "position ASC"
validates_presence_of :title
47 db/migrate/20110713170608_add_indexes.rb
View
@@ -0,0 +1,47 @@
+class AddIndexes < ActiveRecord::Migration
+ def self.up
+ add_index :answers, :question_id
+ add_index :answers, :choice_id
+ add_index :answers, :call_id
+
+ add_index :calls, :survey_id
+ add_index :calls, :user_id
+
+ add_index :choices, :question_id
+
+ add_index :dependencies, :question_id
+ add_index :dependencies, :choice_id
+
+ add_index :questions, :section_id
+
+ add_index :roles_users, :role_id
+ add_index :roles_users, :user_id
+
+ add_index :sections, :survey_id
+
+ add_index :surveys, :client_id
+ end
+
+ def self.down
+ remove_index :answers, :question_id
+ remove_index :answers, :choice_id
+ remove_index :answers, :call_id
+
+ remove_index :calls, :survey_id
+ remove_index :calls, :user_id
+
+ remove_index :choices, :question_id
+
+ remove_index :dependencies, :question_id
+ remove_index :dependencies, :choice_id
+
+ remove_index :questions, :section_id
+
+ remove_index :roles_users, :role_id
+ remove_index :roles_users, :user_id
+
+ remove_index :sections, :survey_id
+
+ remove_index :surveys, :client_id
+ end
+end
137 db/schema.rb
View
@@ -10,62 +10,76 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110711145632) do
+ActiveRecord::Schema.define(:version => 20110713170608) do
create_table "answers", :force => true do |t|
- t.integer "question_id"
- t.integer "choice_id"
- t.integer "call_id"
- t.string "body"
- t.timestamp "created_at"
- t.timestamp "updated_at"
+ t.integer "question_id"
+ t.integer "choice_id"
+ t.integer "call_id"
+ t.string "body"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
+ add_index "answers", ["call_id"], :name => "index_answers_on_call_id"
+ add_index "answers", ["choice_id"], :name => "index_answers_on_choice_id"
+ add_index "answers", ["question_id"], :name => "index_answers_on_question_id"
+
create_table "calls", :force => true do |t|
- t.integer "survey_id"
- t.timestamp "created_at"
- t.timestamp "updated_at"
- t.integer "user_id"
- t.datetime "posted_at"
+ t.integer "survey_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "user_id"
+ t.datetime "posted_at"
end
+ add_index "calls", ["survey_id"], :name => "index_calls_on_survey_id"
+ add_index "calls", ["user_id"], :name => "index_calls_on_user_id"
+
create_table "choices", :force => true do |t|
- t.integer "question_id"
- t.string "ext_id"
- t.string "title"
- t.integer "position"
- t.timestamp "created_at"
- t.timestamp "updated_at"
+ t.integer "question_id"
+ t.string "ext_id"
+ t.string "title"
+ t.integer "position"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
+ add_index "choices", ["question_id"], :name => "index_choices_on_question_id"
+
create_table "clients", :force => true do |t|
- t.string "name"
- t.timestamp "created_at"
- t.timestamp "updated_at"
+ t.string "name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "dependencies", :force => true do |t|
- t.integer "question_id"
- t.integer "choice_id"
- t.timestamp "created_at"
- t.timestamp "updated_at"
+ t.integer "question_id"
+ t.integer "choice_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
+ add_index "dependencies", ["choice_id"], :name => "index_dependencies_on_choice_id"
+ add_index "dependencies", ["question_id"], :name => "index_dependencies_on_question_id"
+
create_table "questions", :force => true do |t|
- t.string "ext_id"
- t.string "typ"
- t.string "title"
- t.integer "position"
- t.integer "section_id"
- t.timestamp "created_at"
- t.timestamp "updated_at"
- t.boolean "required"
+ t.string "ext_id"
+ t.string "typ"
+ t.string "title"
+ t.integer "position"
+ t.integer "section_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.boolean "required"
end
+ add_index "questions", ["section_id"], :name => "index_questions_on_section_id"
+
create_table "roles", :force => true do |t|
- t.string "name"
- t.timestamp "created_at"
- t.timestamp "updated_at"
+ t.string "name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "roles_users", :id => false, :force => true do |t|
@@ -73,35 +87,42 @@
t.integer "user_id"
end
+ add_index "roles_users", ["role_id"], :name => "index_roles_users_on_role_id"
+ add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
+
create_table "sections", :force => true do |t|
- t.string "title"
- t.integer "position"
- t.integer "survey_id"
- t.timestamp "created_at"
- t.timestamp "updated_at"
+ t.string "title"
+ t.integer "position"
+ t.integer "survey_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
+ add_index "sections", ["survey_id"], :name => "index_sections_on_survey_id"
+
create_table "surveys", :force => true do |t|
- t.string "ext_id"
- t.string "title"
- t.integer "client_id"
- t.timestamp "created_at"
- t.timestamp "updated_at"
+ t.string "ext_id"
+ t.string "title"
+ t.integer "client_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
+ add_index "surveys", ["client_id"], :name => "index_surveys_on_client_id"
+
create_table "users", :force => true do |t|
- t.string "email", :default => "", :null => false
- t.string "encrypted_password", :limit => 128, :default => "", :null => false
- t.string "reset_password_token"
- t.timestamp "reset_password_sent_at"
- t.timestamp "remember_created_at"
- t.integer "sign_in_count", :default => 0
- t.timestamp "current_sign_in_at"
- t.timestamp "last_sign_in_at"
- t.string "current_sign_in_ip"
- t.string "last_sign_in_ip"
- t.timestamp "created_at"
- t.timestamp "updated_at"
+ t.string "email", :default => "", :null => false
+ t.string "encrypted_password", :limit => 128, :default => "", :null => false
+ t.string "reset_password_token"
+ t.datetime "reset_password_sent_at"
+ t.datetime "remember_created_at"
+ t.integer "sign_in_count", :default => 0
+ t.datetime "current_sign_in_at"
+ t.datetime "last_sign_in_at"
+ t.string "current_sign_in_ip"
+ t.string "last_sign_in_ip"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
Please sign in to comment.
Something went wrong with that request. Please try again.