diff --git a/app/controllers/dashboard/home_controller.rb b/app/controllers/dashboard/home_controller.rb index 897c1c6..89c50aa 100644 --- a/app/controllers/dashboard/home_controller.rb +++ b/app/controllers/dashboard/home_controller.rb @@ -31,7 +31,7 @@ module Dashboard def schools if district.present? - district.dashboard_schools.order(:name).map do |school| + district.schools.order(:name).map do |school| [school.name, school.id] end else diff --git a/app/models/dashboard/admin_data_value.rb b/app/models/dashboard/admin_data_value.rb index 8eea0b6..cb2a437 100644 --- a/app/models/dashboard/admin_data_value.rb +++ b/app/models/dashboard/admin_data_value.rb @@ -1,6 +1,6 @@ module Dashboard class AdminDataValue < ApplicationRecord - belongs_to :dashboard_school + belongs_to :school belongs_to :dashboard_admin_data_item belongs_to :dashboard_academic_year diff --git a/app/models/dashboard/district.rb b/app/models/dashboard/district.rb index 8dedcc0..13c613a 100644 --- a/app/models/dashboard/district.rb +++ b/app/models/dashboard/district.rb @@ -1,7 +1,8 @@ module Dashboard class District < ApplicationRecord + self.table_name = "districts" + has_many :schools, class_name: "Dashboard::School" has_many :schools, class_name: "Dashboard::School" - has_many :dashboard_schools, class_name: "Dashboard::School" validates :name, presence: true diff --git a/app/models/dashboard/respondent.rb b/app/models/dashboard/respondent.rb index 2312f69..2a7c3eb 100644 --- a/app/models/dashboard/respondent.rb +++ b/app/models/dashboard/respondent.rb @@ -1,6 +1,6 @@ module Dashboard class Respondent < ApplicationRecord - belongs_to :dashboard_school + belongs_to :school belongs_to :dashboard_academic_year validates :school, uniqueness: { scope: :academic_year } diff --git a/app/models/dashboard/response_rate.rb b/app/models/dashboard/response_rate.rb index 53a45fb..612a5d3 100644 --- a/app/models/dashboard/response_rate.rb +++ b/app/models/dashboard/response_rate.rb @@ -1,7 +1,7 @@ module Dashboard class ResponseRate < ApplicationRecord belongs_to :dashboard_subcategory - belongs_to :dashboard_school + belongs_to :school belongs_to :dashboard_academic_year end end diff --git a/app/models/dashboard/school.rb b/app/models/dashboard/school.rb index 1a24ae9..f0379af 100644 --- a/app/models/dashboard/school.rb +++ b/app/models/dashboard/school.rb @@ -1,6 +1,7 @@ module Dashboard class School < ApplicationRecord - belongs_to :dashboard_district, class_name: "Dashboard::District" + self.table_name = "schools" + belongs_to :district, class_name: "District", primary_key: :id has_many :dashboard_survey_item_responses, dependent: :delete_all diff --git a/app/models/dashboard/score.rb b/app/models/dashboard/score.rb index 7dec3f4..b3eb263 100644 --- a/app/models/dashboard/score.rb +++ b/app/models/dashboard/score.rb @@ -1,7 +1,7 @@ module Dashboard class Score < ApplicationRecord belongs_to :dashboard_measure - belongs_to :dashboard_school + belongs_to :school belongs_to :dashboard_academic_year belongs_to :dashboard_race diff --git a/app/models/dashboard/survey_item_response.rb b/app/models/dashboard/survey_item_response.rb index bec997c..e4771c5 100644 --- a/app/models/dashboard/survey_item_response.rb +++ b/app/models/dashboard/survey_item_response.rb @@ -3,7 +3,7 @@ module Dashboard TEACHER_RESPONSE_THRESHOLD = 2 STUDENT_RESPONSE_THRESHOLD = 10 - belongs_to :dashboard_school + belongs_to :school belongs_to :dashboard_survey_item belongs_to :dashboard_academic_year belongs_to :dashboard_student, optional: true diff --git a/db/migrate/20240104173931_create_dashboard_districts.rb b/db/migrate/20240104173931_create_dashboard_districts.rb index e494169..e3b14cc 100644 --- a/db/migrate/20240104173931_create_dashboard_districts.rb +++ b/db/migrate/20240104173931_create_dashboard_districts.rb @@ -1,6 +1,6 @@ class CreateDashboardDistricts < ActiveRecord::Migration[7.1] def change - create_table :dashboard_districts do |t| + create_table :districts do |t| t.string :name t.string :slug t.integer :qualtrics_code diff --git a/db/migrate/20240104174053_create_dashboard_schools.rb b/db/migrate/20240104174053_create_dashboard_schools.rb index 45814c5..30cd565 100644 --- a/db/migrate/20240104174053_create_dashboard_schools.rb +++ b/db/migrate/20240104174053_create_dashboard_schools.rb @@ -1,8 +1,8 @@ class CreateDashboardSchools < ActiveRecord::Migration[7.1] def change - create_table :dashboard_schools do |t| + create_table :schools do |t| t.string :name - t.references :dashboard_district, null: false, foreign_key: true + t.references :district, null: false, foreign_key: true t.text :description t.string :slug t.integer :qualtrics_code diff --git a/db/migrate/20240104174331_create_dashboard_admin_data_values.rb b/db/migrate/20240104174331_create_dashboard_admin_data_values.rb index f9ec684..cb52616 100644 --- a/db/migrate/20240104174331_create_dashboard_admin_data_values.rb +++ b/db/migrate/20240104174331_create_dashboard_admin_data_values.rb @@ -2,7 +2,7 @@ class CreateDashboardAdminDataValues < ActiveRecord::Migration[7.1] def change create_table :dashboard_admin_data_values do |t| t.float :likert_score - t.references :dashboard_school, null: false, foreign_key: true + t.references :school, null: false, foreign_key: true t.references :dashboard_admin_data_item, null: false, foreign_key: true t.references :dashboard_academic_year, null: false, foreign_key: true diff --git a/db/migrate/20240104181617_create_dashboard_respondents.rb b/db/migrate/20240104181617_create_dashboard_respondents.rb index 5c54156..2092e1a 100644 --- a/db/migrate/20240104181617_create_dashboard_respondents.rb +++ b/db/migrate/20240104181617_create_dashboard_respondents.rb @@ -1,7 +1,7 @@ class CreateDashboardRespondents < ActiveRecord::Migration[7.1] def change create_table :dashboard_respondents do |t| - t.references :dashboard_school, null: false, foreign_key: true + t.references :school, null: false, foreign_key: true t.references :dashboard_academic_year, null: false, foreign_key: true t.integer :total_students t.float :total_teachers diff --git a/db/migrate/20240104181856_create_dashboard_response_rates.rb b/db/migrate/20240104181856_create_dashboard_response_rates.rb index cb3ef71..2195cc5 100644 --- a/db/migrate/20240104181856_create_dashboard_response_rates.rb +++ b/db/migrate/20240104181856_create_dashboard_response_rates.rb @@ -2,7 +2,7 @@ class CreateDashboardResponseRates < ActiveRecord::Migration[7.1] def change create_table :dashboard_response_rates do |t| t.references :dashboard_subcategory, null: false, foreign_key: true - t.references :dashboard_school, null: false, foreign_key: true + t.references :school, null: false, foreign_key: true t.references :dashboard_academic_year, null: false, foreign_key: true t.float :school_response_rate t.float :teacher_response_rate diff --git a/db/migrate/20240104192128_create_dashboard_survey_item_responses.rb b/db/migrate/20240104192128_create_dashboard_survey_item_responses.rb index b2d46d7..57efcff 100644 --- a/db/migrate/20240104192128_create_dashboard_survey_item_responses.rb +++ b/db/migrate/20240104192128_create_dashboard_survey_item_responses.rb @@ -2,7 +2,7 @@ class CreateDashboardSurveyItemResponses < ActiveRecord::Migration[7.1] def change create_table :dashboard_survey_item_responses do |t| t.integer :likert_score - t.references :dashboard_school, null: false, foreign_key: true + t.references :school, null: false, foreign_key: true t.references :dashboard_survey_item, null: false, foreign_key: true t.references :dashboard_academic_year, null: false, foreign_key: true t.references :dashboard_student, foreign_key: true diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index d5d7af1..9992b75 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -10,10 +10,18 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do +ActiveRecord::Schema[7.1].define(version: 2024_01_05_041641) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "children", force: :cascade do |t| + t.text "text" + t.bigint "parent_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["parent_id"], name: "index_children_on_parent_id" + end + create_table "dashboard_academic_years", force: :cascade do |t| t.string "range" t.datetime "created_at", null: false @@ -37,21 +45,14 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do create_table "dashboard_admin_data_values", force: :cascade do |t| t.float "likert_score" - t.bigint "dashboard_school_id", null: false + t.bigint "school_id", null: false t.bigint "dashboard_admin_data_item_id", null: false t.bigint "dashboard_academic_year_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["dashboard_academic_year_id"], name: "idx_on_dashboard_academic_year_id_1de27231d5" t.index ["dashboard_admin_data_item_id"], name: "idx_on_dashboard_admin_data_item_id_edae2faad3" - t.index ["dashboard_school_id"], name: "index_dashboard_admin_data_values_on_dashboard_school_id" - end - - create_table "dashboard_atoms", force: :cascade do |t| - t.integer "survey_item" - t.text "text" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.index ["school_id"], name: "index_dashboard_admin_data_values_on_school_id" end create_table "dashboard_categories", force: :cascade do |t| @@ -64,14 +65,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do t.datetime "updated_at", null: false end - create_table "dashboard_districts", force: :cascade do |t| - t.string "name" - t.string "slug" - t.integer "qualtrics_code" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - create_table "dashboard_ells", force: :cascade do |t| t.string "designation" t.string "slug" @@ -119,7 +112,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do end create_table "dashboard_respondents", force: :cascade do |t| - t.bigint "dashboard_school_id", null: false + t.bigint "school_id", null: false t.bigint "dashboard_academic_year_id", null: false t.integer "total_students" t.float "total_teachers" @@ -140,20 +133,20 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["dashboard_academic_year_id"], name: "index_dashboard_respondents_on_dashboard_academic_year_id" - t.index ["dashboard_school_id"], name: "index_dashboard_respondents_on_dashboard_school_id" + t.index ["school_id"], name: "index_dashboard_respondents_on_school_id" end create_table "dashboard_response_rates", force: :cascade do |t| t.bigint "dashboard_subcategory_id", null: false - t.bigint "dashboard_school_id", null: false + t.bigint "school_id", null: false t.bigint "dashboard_academic_year_id", null: false t.float "school_response_rate" t.float "teacher_response_rate" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["dashboard_academic_year_id"], name: "index_dashboard_response_rates_on_dashboard_academic_year_id" - t.index ["dashboard_school_id"], name: "index_dashboard_response_rates_on_dashboard_school_id" t.index ["dashboard_subcategory_id"], name: "index_dashboard_response_rates_on_dashboard_subcategory_id" + t.index ["school_id"], name: "index_dashboard_response_rates_on_school_id" end create_table "dashboard_scales", force: :cascade do |t| @@ -164,19 +157,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do t.index ["dashboard_measure_id"], name: "index_dashboard_scales_on_dashboard_measure_id" end - create_table "dashboard_schools", force: :cascade do |t| - t.string "name" - t.bigint "dashboard_district_id", null: false - t.text "description" - t.string "slug" - t.integer "qualtrics_code" - t.integer "dese_id" - t.boolean "is_hs" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["dashboard_district_id"], name: "index_dashboard_schools_on_dashboard_district_id" - end - create_table "dashboard_scores", force: :cascade do |t| t.float "average" t.boolean "meets_teacher_threshold" @@ -221,7 +201,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do create_table "dashboard_survey_item_responses", force: :cascade do |t| t.integer "likert_score" - t.bigint "dashboard_school_id", null: false + t.bigint "school_id", null: false t.bigint "dashboard_survey_item_id", null: false t.bigint "dashboard_academic_year_id", null: false t.bigint "dashboard_student_id" @@ -238,10 +218,10 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do t.index ["dashboard_ell_id"], name: "index_dashboard_survey_item_responses_on_dashboard_ell_id" t.index ["dashboard_gender_id"], name: "index_dashboard_survey_item_responses_on_dashboard_gender_id" t.index ["dashboard_income_id"], name: "index_dashboard_survey_item_responses_on_dashboard_income_id" - t.index ["dashboard_school_id"], name: "index_dashboard_survey_item_responses_on_dashboard_school_id" t.index ["dashboard_sped_id"], name: "index_dashboard_survey_item_responses_on_dashboard_sped_id" t.index ["dashboard_student_id"], name: "index_dashboard_survey_item_responses_on_dashboard_student_id" t.index ["dashboard_survey_item_id"], name: "idx_on_dashboard_survey_item_id_3f6652fbc6" + t.index ["school_id"], name: "index_dashboard_survey_item_responses_on_school_id" end create_table "dashboard_survey_items", force: :cascade do |t| @@ -258,18 +238,45 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do t.index ["dashboard_scale_id"], name: "index_dashboard_survey_items_on_dashboard_scale_id" end + create_table "districts", force: :cascade do |t| + t.string "name" + t.string "slug" + t.integer "qualtrics_code" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "parents", force: :cascade do |t| + t.text "text" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "schools", force: :cascade do |t| + t.string "name" + t.bigint "district_id", null: false + t.text "description" + t.string "slug" + t.integer "qualtrics_code" + t.integer "dese_id" + t.boolean "is_hs" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["district_id"], name: "index_schools_on_district_id" + end + + add_foreign_key "children", "parents" add_foreign_key "dashboard_admin_data_items", "dashboard_scales" add_foreign_key "dashboard_admin_data_values", "dashboard_academic_years" add_foreign_key "dashboard_admin_data_values", "dashboard_admin_data_items" - add_foreign_key "dashboard_admin_data_values", "dashboard_schools" + add_foreign_key "dashboard_admin_data_values", "schools" add_foreign_key "dashboard_measures", "dashboard_subcategories" add_foreign_key "dashboard_respondents", "dashboard_academic_years" - add_foreign_key "dashboard_respondents", "dashboard_schools" + add_foreign_key "dashboard_respondents", "schools" add_foreign_key "dashboard_response_rates", "dashboard_academic_years" - add_foreign_key "dashboard_response_rates", "dashboard_schools" add_foreign_key "dashboard_response_rates", "dashboard_subcategories" + add_foreign_key "dashboard_response_rates", "schools" add_foreign_key "dashboard_scales", "dashboard_measures" - add_foreign_key "dashboard_schools", "dashboard_districts" add_foreign_key "dashboard_student_races", "dashboard_races" add_foreign_key "dashboard_student_races", "dashboard_students" add_foreign_key "dashboard_subcategories", "dashboard_categories", column: "dashboard_categories_id" @@ -277,9 +284,10 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_05_040909) do add_foreign_key "dashboard_survey_item_responses", "dashboard_ells" add_foreign_key "dashboard_survey_item_responses", "dashboard_genders" add_foreign_key "dashboard_survey_item_responses", "dashboard_incomes" - add_foreign_key "dashboard_survey_item_responses", "dashboard_schools" add_foreign_key "dashboard_survey_item_responses", "dashboard_speds" add_foreign_key "dashboard_survey_item_responses", "dashboard_students" add_foreign_key "dashboard_survey_item_responses", "dashboard_survey_items" + add_foreign_key "dashboard_survey_item_responses", "schools" add_foreign_key "dashboard_survey_items", "dashboard_scales" + add_foreign_key "schools", "districts" end