diff --git a/db/migrate/20180313120831_add_required_indices.rb b/db/migrate/20180313120831_add_required_indices.rb new file mode 100644 index 0000000..a33dfa4 --- /dev/null +++ b/db/migrate/20180313120831_add_required_indices.rb @@ -0,0 +1,16 @@ +class AddRequiredIndices < ActiveRecord::Migration + def change + #answers + add_index :answers, :question_id + add_index :answers, :plan_id + + #perms + remove_index :perms, name: :index_perms_on_name + remove_index :perms, name: :index_roles_on_name_and_resource_type_and_resource_id + + #plans_guidance_groups + add_index :plans_guidance_groups, [:guidance_group_id, :plan_id] + + end +end + diff --git a/db/schema.rb b/db/schema.rb index 5a1c1e3..b38c962 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180312141558) do +ActiveRecord::Schema.define(version: 20180313120831) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -25,7 +25,7 @@ t.datetime "updated_at" end - add_index "annotations", ["question_id"], name: "index_annotations_on_question_id", using: :btree + add_index "annotations", ["question_id"], name: "index_annotations_on_question_id" create_table "answers", force: :cascade do |t| t.text "text" @@ -37,12 +37,15 @@ t.integer "lock_version", default: 0 end + add_index "answers", ["plan_id"], name: "index_answers_on_plan_id" + add_index "answers", ["question_id"], name: "index_answers_on_question_id" + create_table "answers_question_options", id: false, force: :cascade do |t| t.integer "answer_id", null: false t.integer "question_option_id", null: false end - add_index "answers_question_options", ["answer_id"], name: "index_answers_question_options_on_answer_id", using: :btree + add_index "answers_question_options", ["answer_id"], name: "index_answers_question_options_on_answer_id" create_table "exported_plans", force: :cascade do |t| t.integer "plan_id" @@ -81,9 +84,9 @@ t.datetime "created_at" end - add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true, using: :btree - add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id", using: :btree - add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree + add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true + add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id" + add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type" create_table "guidance_groups", force: :cascade do |t| t.string "name" @@ -94,7 +97,7 @@ t.boolean "published" end - add_index "guidance_groups", ["org_id"], name: "index_guidance_groups_on_org_id", using: :btree + add_index "guidance_groups", ["org_id"], name: "index_guidance_groups_on_org_id" create_table "guidances", force: :cascade do |t| t.text "text" @@ -105,7 +108,7 @@ t.boolean "published" end - add_index "guidances", ["guidance_group_id"], name: "index_guidances_on_guidance_group_id", using: :btree + add_index "guidances", ["guidance_group_id"], name: "index_guidances_on_guidance_group_id" create_table "identifier_schemes", force: :cascade do |t| t.string "name" @@ -134,7 +137,7 @@ t.datetime "updated_at" end - add_index "notes", ["answer_id"], name: "index_notes_on_answer_id", using: :btree + add_index "notes", ["answer_id"], name: "index_notes_on_answer_id" create_table "org_identifiers", force: :cascade do |t| t.string "identifier" @@ -152,7 +155,7 @@ t.datetime "updated_at" end - add_index "org_token_permissions", ["org_id"], name: "index_org_token_permissions_on_org_id", using: :btree + add_index "org_token_permissions", ["org_id"], name: "index_org_token_permissions_on_org_id" create_table "orgs", force: :cascade do |t| t.string "name" @@ -185,9 +188,6 @@ t.datetime "updated_at", null: false end - add_index "perms", ["name"], name: "index_perms_on_name", using: :btree - add_index "perms", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree - create_table "phases", force: :cascade do |t| t.string "title" t.text "description" @@ -199,7 +199,7 @@ t.boolean "modifiable" end - add_index "phases", ["template_id"], name: "index_phases_on_template_id", using: :btree + add_index "phases", ["template_id"], name: "index_phases_on_template_id" create_table "plans", force: :cascade do |t| t.string "title" @@ -223,13 +223,15 @@ t.boolean "complete", default: false end - add_index "plans", ["template_id"], name: "index_plans_on_template_id", using: :btree + add_index "plans", ["template_id"], name: "index_plans_on_template_id" create_table "plans_guidance_groups", force: :cascade do |t| t.integer "guidance_group_id" t.integer "plan_id" end + add_index "plans_guidance_groups", ["guidance_group_id", "plan_id"], name: "index_plans_guidance_groups_on_guidance_group_id_and_plan_id" + create_table "prefs", force: :cascade do |t| t.text "settings" t.integer "user_id" @@ -253,7 +255,7 @@ t.datetime "updated_at" end - add_index "question_options", ["question_id"], name: "index_question_options_on_question_id", using: :btree + add_index "question_options", ["question_id"], name: "index_question_options_on_question_id" create_table "questions", force: :cascade do |t| t.text "text" @@ -267,14 +269,14 @@ t.boolean "modifiable" end - add_index "questions", ["section_id"], name: "index_questions_on_section_id", using: :btree + add_index "questions", ["section_id"], name: "index_questions_on_section_id" create_table "questions_themes", id: false, force: :cascade do |t| t.integer "question_id", null: false t.integer "theme_id", null: false end - add_index "questions_themes", ["question_id"], name: "index_questions_themes_on_question_id", using: :btree + add_index "questions_themes", ["question_id"], name: "index_questions_themes_on_question_id" create_table "regions", force: :cascade do |t| t.string "abbreviation" @@ -292,8 +294,8 @@ t.boolean "active", default: true end - add_index "roles", ["plan_id"], name: "index_roles_on_plan_id", using: :btree - add_index "roles", ["user_id"], name: "index_roles_on_user_id", using: :btree + add_index "roles", ["plan_id"], name: "index_roles_on_plan_id" + add_index "roles", ["user_id"], name: "index_roles_on_user_id" create_table "sections", force: :cascade do |t| t.string "title" @@ -306,7 +308,7 @@ t.boolean "modifiable" end - add_index "sections", ["phase_id"], name: "index_sections_on_phase_id", using: :btree + add_index "sections", ["phase_id"], name: "index_sections_on_phase_id" create_table "settings", force: :cascade do |t| t.string "var", null: false @@ -317,7 +319,7 @@ t.datetime "updated_at", null: false end - add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree + add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true create_table "splash_logs", force: :cascade do |t| t.string "destination" @@ -343,8 +345,8 @@ t.text "links", default: "{\"funder\":[], \"sample_plan\":[]}" end - add_index "templates", ["org_id", "dmptemplate_id"], name: "template_organisation_dmptemplate_index", using: :btree - add_index "templates", ["org_id"], name: "index_templates_on_org_id", using: :btree + add_index "templates", ["org_id", "dmptemplate_id"], name: "template_organisation_dmptemplate_index" + add_index "templates", ["org_id"], name: "index_templates_on_org_id" create_table "themes", force: :cascade do |t| t.string "title" @@ -359,8 +361,8 @@ t.integer "guidance_id" end - add_index "themes_in_guidance", ["guidance_id"], name: "index_themes_in_guidance_on_guidance_id", using: :btree - add_index "themes_in_guidance", ["theme_id"], name: "index_themes_in_guidance_on_theme_id", using: :btree + add_index "themes_in_guidance", ["guidance_id"], name: "index_themes_in_guidance_on_guidance_id" + add_index "themes_in_guidance", ["theme_id"], name: "index_themes_in_guidance_on_theme_id" create_table "token_permission_types", force: :cascade do |t| t.string "token_type" @@ -377,7 +379,7 @@ t.integer "identifier_scheme_id" end - add_index "user_identifiers", ["user_id"], name: "index_user_identifiers_on_user_id", using: :btree + add_index "user_identifiers", ["user_id"], name: "index_user_identifiers_on_user_id" create_table "users", force: :cascade do |t| t.string "firstname" @@ -413,15 +415,15 @@ t.string "recovery_email" end - add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree - add_index "users", ["org_id"], name: "index_users_on_org_id", using: :btree + add_index "users", ["email"], name: "index_users_on_email", unique: true + add_index "users", ["org_id"], name: "index_users_on_org_id" create_table "users_perms", id: false, force: :cascade do |t| t.integer "user_id" t.integer "perm_id" end - add_index "users_perms", ["user_id"], name: "index_users_perms_on_user_id", using: :btree + add_index "users_perms", ["user_id"], name: "index_users_perms_on_user_id" add_foreign_key "annotations", "orgs" add_foreign_key "annotations", "questions"