diff --git a/app/models/org.rb b/app/models/org.rb index 36e2bd0..cc259f9 100644 --- a/app/models/org.rb +++ b/app/models/org.rb @@ -11,7 +11,7 @@ # feedback_email_subject :string # feedback_enabled :boolean default(FALSE) # is_other :boolean -# links :text default({"org"=>[]}) +# links :text # logo_file_name :string # logo_name :string # logo_uid :string diff --git a/app/models/settings/template.rb b/app/models/settings/template.rb index 54a272f..d4cab3d 100644 --- a/app/models/settings/template.rb +++ b/app/models/settings/template.rb @@ -10,10 +10,6 @@ # updated_at :datetime not null # target_id :integer not null # -# Indexes -# -# index_settings_on_target_type_and_target_id_and_var (target_type,target_id,var) UNIQUE -# module Settings class Template < RailsSettings::SettingObject diff --git a/app/models/template.rb b/app/models/template.rb index 4816af1..552e415 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -7,7 +7,7 @@ # customization_of :integer # description :text # is_default :boolean -# links :text default({"funder"=>[], "sample_plan"=>[]}) +# links :text # locale :string # published :boolean # title :string diff --git a/app/models/user.rb b/app/models/user.rb index 0d44157..553b685 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,7 +11,7 @@ # confirmed_at :datetime # current_sign_in_at :datetime # current_sign_in_ip :string -# email :string default(""), not null +# email :string(80) default(""), not null # encrypted_password :string default("") # firstname :string # invitation_accepted_at :datetime diff --git a/db/migrate/20180713145319_fix_invalid_mysql_indices.rb b/db/migrate/20180713145319_fix_invalid_mysql_indices.rb new file mode 100644 index 0000000..d2a3250 --- /dev/null +++ b/db/migrate/20180713145319_fix_invalid_mysql_indices.rb @@ -0,0 +1,20 @@ +class FixInvalidMysqlIndices < ActiveRecord::Migration + def up + if index_exists?("settings", ["target_type", "target_id", "var"]) + remove_index "settings", ["target_type", "target_id", "var"] + + add_index "settings", ["target_type", "target_id"], + name: "index_settings_on_target_type_and_target_id", + unique: true + end + end + + def down + if index_exists?("settings", ["target_type", "target_id"]) + remove_index "settings", ["target_type", "target_id"] + add_index "settings", ["target_type", "target_id", "var"], + name: "index_settings_on_target_type_and_target_id_and_var", + unique: true + end + end +end diff --git a/db/migrate/20180713145547_remove_defaults_from_links.rb b/db/migrate/20180713145547_remove_defaults_from_links.rb new file mode 100644 index 0000000..e9fea71 --- /dev/null +++ b/db/migrate/20180713145547_remove_defaults_from_links.rb @@ -0,0 +1,12 @@ +class RemoveDefaultsFromLinks < ActiveRecord::Migration + def up + change_column :templates, :links, :text, default: nil + change_column :orgs, :links, :text, default: nil + end + def down + change_column :templates, :links, :text, + default: "{\"funder\":[], \"sample_plan\":[]}" + change_column :orgs, :links, :text, + default: "{\"funder\":[], \"sample_plan\":[]}" + end +end diff --git a/db/migrate/20180713161007_remove_settings_indices.rb b/db/migrate/20180713161007_remove_settings_indices.rb new file mode 100644 index 0000000..62dfbba --- /dev/null +++ b/db/migrate/20180713161007_remove_settings_indices.rb @@ -0,0 +1,11 @@ +class RemoveSettingsIndices < ActiveRecord::Migration + def up + remove_index "settings", ["target_type", "target_id"] + end + def down + add_index "settings", ["target_type", "target_id"], + name: "index_settings_on_target_type_and_target_id", + unique: true, + using: :btree + end +end diff --git a/db/migrate/20180713164120_add_length_constraints_to_users_email.rb b/db/migrate/20180713164120_add_length_constraints_to_users_email.rb new file mode 100644 index 0000000..00a9afa --- /dev/null +++ b/db/migrate/20180713164120_add_length_constraints_to_users_email.rb @@ -0,0 +1,8 @@ +class AddLengthConstraintsToUsersEmail < ActiveRecord::Migration + def up + change_column :users, :email, :string, default: "", null: false, limit: 80 + end + def down + change_column :users, :email, :string, default: "", null: false, limit: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index 8864996..2d5eebe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180508151824) do +ActiveRecord::Schema.define(version: 20180713164120) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" create_table "annotations", force: :cascade do |t| t.integer "question_id" @@ -22,7 +25,7 @@ t.datetime "updated_at" end - add_index "annotations", ["question_id"], name: "index_annotations_on_question_id" + add_index "annotations", ["question_id"], name: "index_annotations_on_question_id", using: :btree create_table "answers", force: :cascade do |t| t.text "text" @@ -34,15 +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" + add_index "answers", ["plan_id"], name: "index_answers_on_plan_id", using: :btree + add_index "answers", ["question_id"], name: "index_answers_on_question_id", using: :btree 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" + add_index "answers_question_options", ["answer_id"], name: "index_answers_question_options_on_answer_id", using: :btree create_table "exported_plans", force: :cascade do |t| t.integer "plan_id" @@ -83,7 +86,7 @@ t.boolean "published" end - add_index "guidance_groups", ["org_id"], name: "index_guidance_groups_on_org_id" + add_index "guidance_groups", ["org_id"], name: "index_guidance_groups_on_org_id", using: :btree create_table "guidances", force: :cascade do |t| t.text "text" @@ -94,7 +97,7 @@ t.boolean "published" end - add_index "guidances", ["guidance_group_id"], name: "index_guidances_on_guidance_group_id" + add_index "guidances", ["guidance_group_id"], name: "index_guidances_on_guidance_group_id", using: :btree create_table "identifier_schemes", force: :cascade do |t| t.string "name" @@ -123,7 +126,7 @@ t.datetime "updated_at" end - add_index "notes", ["answer_id"], name: "index_notes_on_answer_id" + add_index "notes", ["answer_id"], name: "index_notes_on_answer_id", using: :btree create_table "notification_acknowledgements", force: :cascade do |t| t.integer "user_id" @@ -132,8 +135,8 @@ t.datetime "updated_at" end - add_index "notification_acknowledgements", ["notification_id"], name: "index_notification_acknowledgements_on_notification_id" - add_index "notification_acknowledgements", ["user_id"], name: "index_notification_acknowledgements_on_user_id" + add_index "notification_acknowledgements", ["notification_id"], name: "index_notification_acknowledgements_on_notification_id", using: :btree + add_index "notification_acknowledgements", ["user_id"], name: "index_notification_acknowledgements_on_user_id", using: :btree create_table "notifications", force: :cascade do |t| t.integer "notification_type" @@ -163,15 +166,15 @@ t.datetime "updated_at" end - add_index "org_token_permissions", ["org_id"], name: "index_org_token_permissions_on_org_id" + add_index "org_token_permissions", ["org_id"], name: "index_org_token_permissions_on_org_id", using: :btree create_table "orgs", force: :cascade do |t| t.string "name" t.string "abbreviation" t.string "target_url" t.string "wayfless_entity" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "parent_id" t.boolean "is_other" t.string "sort_name" @@ -182,7 +185,7 @@ t.string "logo_uid" t.string "logo_name" t.string "contact_email" - t.integer "org_type", default: 0, null: false + t.integer "org_type", default: 0, null: false t.text "links" t.string "contact_name" t.boolean "feedback_enabled", default: false @@ -207,7 +210,7 @@ t.boolean "modifiable" end - add_index "phases", ["template_id"], name: "index_phases_on_template_id" + add_index "phases", ["template_id"], name: "index_phases_on_template_id", using: :btree create_table "plans", force: :cascade do |t| t.string "title" @@ -231,14 +234,14 @@ t.boolean "complete", default: false end - add_index "plans", ["template_id"], name: "index_plans_on_template_id" + add_index "plans", ["template_id"], name: "index_plans_on_template_id", using: :btree 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" + add_index "plans_guidance_groups", ["guidance_group_id", "plan_id"], name: "index_plans_guidance_groups_on_guidance_group_id_and_plan_id", using: :btree create_table "prefs", force: :cascade do |t| t.text "settings" @@ -263,7 +266,7 @@ t.datetime "updated_at" end - add_index "question_options", ["question_id"], name: "index_question_options_on_question_id" + add_index "question_options", ["question_id"], name: "index_question_options_on_question_id", using: :btree create_table "questions", force: :cascade do |t| t.text "text" @@ -277,14 +280,14 @@ t.boolean "modifiable" end - add_index "questions", ["section_id"], name: "index_questions_on_section_id" + add_index "questions", ["section_id"], name: "index_questions_on_section_id", using: :btree 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" + add_index "questions_themes", ["question_id"], name: "index_questions_themes_on_question_id", using: :btree create_table "regions", force: :cascade do |t| t.string "abbreviation" @@ -302,8 +305,8 @@ t.boolean "active", default: true end - add_index "roles", ["plan_id"], name: "index_roles_on_plan_id" - add_index "roles", ["user_id"], name: "index_roles_on_user_id" + 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 create_table "sections", force: :cascade do |t| t.string "title" @@ -316,7 +319,7 @@ t.boolean "modifiable" end - add_index "sections", ["phase_id"], name: "index_sections_on_phase_id" + add_index "sections", ["phase_id"], name: "index_sections_on_phase_id", using: :btree create_table "settings", force: :cascade do |t| t.string "var", null: false @@ -327,8 +330,6 @@ 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 - create_table "splash_logs", force: :cascade do |t| t.string "destination" t.datetime "created_at", null: false @@ -352,11 +353,11 @@ t.text "links" end - add_index "templates", ["customization_of", "version", "org_id"], name: "index_templates_on_customization_of_and_version_and_org_id", unique: true - add_index "templates", ["family_id", "version"], name: "index_templates_on_family_id_and_version", unique: true - add_index "templates", ["family_id"], name: "index_templates_on_family_id" - add_index "templates", ["org_id", "family_id"], name: "template_organisation_dmptemplate_index" - add_index "templates", ["org_id"], name: "index_templates_on_org_id" + add_index "templates", ["customization_of", "version", "org_id"], name: "index_templates_on_customization_of_and_version_and_org_id", unique: true, using: :btree + add_index "templates", ["family_id", "version"], name: "index_templates_on_family_id_and_version", unique: true, using: :btree + add_index "templates", ["family_id"], name: "index_templates_on_family_id", using: :btree + add_index "templates", ["org_id", "family_id"], name: "template_organisation_dmptemplate_index", using: :btree + add_index "templates", ["org_id"], name: "index_templates_on_org_id", using: :btree create_table "themes", force: :cascade do |t| t.string "title" @@ -371,8 +372,8 @@ t.integer "guidance_id" end - 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" + 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 create_table "token_permission_types", force: :cascade do |t| t.string "token_type" @@ -389,21 +390,21 @@ t.integer "identifier_scheme_id" end - add_index "user_identifiers", ["user_id"], name: "index_user_identifiers_on_user_id" + add_index "user_identifiers", ["user_id"], name: "index_user_identifiers_on_user_id", using: :btree create_table "users", force: :cascade do |t| t.string "firstname" t.string "surname" - t.string "email", default: "", null: false + t.string "email", limit: 80, default: "", null: false t.string "orcid_id" t.string "shibboleth_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "encrypted_password", default: "" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "encrypted_password", default: "" t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0 + 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" @@ -423,11 +424,11 @@ t.string "invited_by_type" t.integer "language_id" t.string "recovery_email" - t.boolean "active", default: true + t.boolean "active", default: true end - add_index "users", ["email"], name: "index_users_on_email", unique: true - add_index "users", ["org_id"], name: "index_users_on_org_id" + 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 create_table "users_perms", id: false, force: :cascade do |t| t.integer "user_id" @@ -441,6 +442,8 @@ add_foreign_key "answers", "plans" add_foreign_key "answers", "questions" add_foreign_key "answers", "users" + add_foreign_key "answers_question_options", "answers" + add_foreign_key "answers_question_options", "question_options" add_foreign_key "guidance_groups", "orgs" add_foreign_key "guidances", "guidance_groups" add_foreign_key "notes", "answers" @@ -460,6 +463,8 @@ add_foreign_key "question_options", "questions" add_foreign_key "questions", "question_formats" add_foreign_key "questions", "sections" + add_foreign_key "questions_themes", "questions" + add_foreign_key "questions_themes", "themes" add_foreign_key "roles", "plans" add_foreign_key "roles", "users" add_foreign_key "sections", "phases" @@ -470,4 +475,6 @@ add_foreign_key "user_identifiers", "users" add_foreign_key "users", "languages" add_foreign_key "users", "orgs" + add_foreign_key "users_perms", "perms" + add_foreign_key "users_perms", "users" end