diff --git a/app/models/question.rb b/app/models/question.rb index fe377ff..c1759cd 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -3,25 +3,26 @@ # # Table name: questions # -# id :integer not null, primary key -# text :text -# default_value :text -# number :integer -# section_id :integer -# created_at :datetime -# updated_at :datetime -# question_format_id :integer -# option_comment_display :boolean default("true") -# modifiable :boolean -# versionable_id :string(36) -# structured :boolean default("false"), not null -# schema_id :integer +# id :integer not null, primary key +# text :text +# default_value :text +# number :integer +# section_id :integer +# created_at :datetime +# updated_at :datetime +# question_format_id :integer +# option_comment_display :boolean default("true") +# modifiable :boolean +# versionable_id :string(36) +# structured :boolean default("false"), not null +# structured_data_schema_id :integer # # Indexes # -# index_questions_on_versionable_id (versionable_id) -# questions_question_format_id_idx (question_format_id) -# questions_section_id_idx (section_id) +# index_questions_on_structured_data_schema_id (structured_data_schema_id) +# index_questions_on_versionable_id (versionable_id) +# questions_question_format_id_idx (question_format_id) +# questions_section_id_idx (section_id) # class Question < ActiveRecord::Base diff --git a/app/models/structured_answer.rb b/app/models/structured_answer.rb index 0bde9f3..e3ee051 100644 --- a/app/models/structured_answer.rb +++ b/app/models/structured_answer.rb @@ -9,6 +9,11 @@ # created_at :datetime not null # updated_at :datetime not null # +# Indexes +# +# index_structured_answers_on_answer_id (answer_id) +# index_structured_answers_on_structured_data_schema_id (structured_data_schema_id) +# class StructuredAnswer < ActiveRecord::Base belongs_to :answer diff --git a/app/models/structured_data_schema.rb b/app/models/structured_data_schema.rb index fa22124..1e24a03 100644 --- a/app/models/structured_data_schema.rb +++ b/app/models/structured_data_schema.rb @@ -12,6 +12,10 @@ # created_at :datetime not null # updated_at :datetime not null # +# Indexes +# +# index_structured_data_schemas_on_org_id (org_id) +# class StructuredDataSchema < ActiveRecord::Base belongs_to :org diff --git a/db/migrate/20200120134348_add_schema_id_to_questions.rb b/db/migrate/20200120134348_add_schema_id_to_questions.rb index e015c9c..af6e6ce 100644 --- a/db/migrate/20200120134348_add_schema_id_to_questions.rb +++ b/db/migrate/20200120134348_add_schema_id_to_questions.rb @@ -1,5 +1,5 @@ class AddSchemaIdToQuestions < ActiveRecord::Migration def change - add_reference :questions, :schema_id, foreign_key: true, index: true + add_reference :questions, :structured_data_schema, foreign_key: true, index: true end end diff --git a/db/schema.rb b/db/schema.rb index 7833b11..9941f1b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -285,15 +285,16 @@ t.datetime "created_at" t.datetime "updated_at" t.integer "question_format_id" - t.boolean "option_comment_display", default: true + t.boolean "option_comment_display", default: true t.boolean "modifiable" - t.string "versionable_id", limit: 36 - t.boolean "structured", default: false, null: false - t.integer "schema_id" + t.string "versionable_id", limit: 36 + t.boolean "structured", default: false, null: false + t.integer "structured_data_schema_id" end add_index "questions", ["question_format_id"], name: "questions_question_format_id_idx", using: :btree add_index "questions", ["section_id"], name: "questions_section_id_idx", using: :btree + add_index "questions", ["structured_data_schema_id"], name: "index_questions_on_structured_data_schema_id", using: :btree add_index "questions", ["versionable_id"], name: "index_questions_on_versionable_id", using: :btree create_table "questions_themes", id: false, force: :cascade do |t| @@ -420,6 +421,9 @@ t.datetime "updated_at", null: false end + add_index "structured_answers", ["answer_id"], name: "index_structured_answers_on_answer_id", using: :btree + add_index "structured_answers", ["structured_data_schema_id"], name: "index_structured_answers_on_structured_data_schema_id", using: :btree + create_table "structured_data_schemas", force: :cascade do |t| t.string "label" t.string "name" @@ -431,6 +435,8 @@ t.datetime "updated_at", null: false end + add_index "structured_data_schemas", ["org_id"], name: "index_structured_data_schemas_on_org_id", using: :btree + create_table "templates", force: :cascade do |t| t.string "title" t.text "description" @@ -561,6 +567,7 @@ add_foreign_key "question_options", "questions" add_foreign_key "questions", "question_formats" add_foreign_key "questions", "sections" + add_foreign_key "questions", "structured_data_schemas" add_foreign_key "questions_themes", "questions" add_foreign_key "questions_themes", "themes" add_foreign_key "research_outputs", "plans" @@ -570,6 +577,9 @@ add_foreign_key "sections", "phases" add_foreign_key "static_page_contents", "languages" add_foreign_key "static_page_contents", "static_pages" + add_foreign_key "structured_answers", "answers" + add_foreign_key "structured_answers", "structured_data_schemas" + add_foreign_key "structured_data_schemas", "orgs" add_foreign_key "templates", "orgs" add_foreign_key "themes_in_guidance", "guidances" add_foreign_key "themes_in_guidance", "themes" diff --git a/spec/factories/questions.rb b/spec/factories/questions.rb index 2e545d6..dde00b3 100644 --- a/spec/factories/questions.rb +++ b/spec/factories/questions.rb @@ -2,25 +2,26 @@ # # Table name: questions # -# id :integer not null, primary key -# text :text -# default_value :text -# number :integer -# section_id :integer -# created_at :datetime -# updated_at :datetime -# question_format_id :integer -# option_comment_display :boolean default("true") -# modifiable :boolean -# versionable_id :string(36) -# structured :boolean default("false"), not null -# schema_id :integer +# id :integer not null, primary key +# text :text +# default_value :text +# number :integer +# section_id :integer +# created_at :datetime +# updated_at :datetime +# question_format_id :integer +# option_comment_display :boolean default("true") +# modifiable :boolean +# versionable_id :string(36) +# structured :boolean default("false"), not null +# structured_data_schema_id :integer # # Indexes # -# index_questions_on_versionable_id (versionable_id) -# questions_question_format_id_idx (question_format_id) -# questions_section_id_idx (section_id) +# index_questions_on_structured_data_schema_id (structured_data_schema_id) +# index_questions_on_versionable_id (versionable_id) +# questions_question_format_id_idx (question_format_id) +# questions_section_id_idx (section_id) # FactoryBot.define do diff --git a/spec/factories/structured_answers.rb b/spec/factories/structured_answers.rb index cc2ecc1..89c53e1 100644 --- a/spec/factories/structured_answers.rb +++ b/spec/factories/structured_answers.rb @@ -9,6 +9,11 @@ # created_at :datetime not null # updated_at :datetime not null # +# Indexes +# +# index_structured_answers_on_answer_id (answer_id) +# index_structured_answers_on_structured_data_schema_id (structured_data_schema_id) +# FactoryBot.define do factory :structured_answer do diff --git a/spec/factories/structured_data_schemas.rb b/spec/factories/structured_data_schemas.rb index 690bc45..d62ce12 100644 --- a/spec/factories/structured_data_schemas.rb +++ b/spec/factories/structured_data_schemas.rb @@ -12,6 +12,10 @@ # created_at :datetime not null # updated_at :datetime not null # +# Indexes +# +# index_structured_data_schemas_on_org_id (org_id) +# FactoryBot.define do factory :structured_data_schema do