Add foreign keys and an index to StructuredError(Attributes)

These changes will ensure a better data consistency and faster access. We further ensure that records should be deleted properly.
This commit is contained in:
Sebastian Serth
2023-03-20 23:50:12 +01:00
parent 5a36e57b9f
commit e3e6fc3af1
5 changed files with 26 additions and 3 deletions

View File

@ -4,7 +4,7 @@ class StructuredError < ApplicationRecord
belongs_to :error_template
belongs_to :submission
has_many :structured_error_attributes
has_many :structured_error_attributes, dependent: :destroy
def self.create_from_template(template, message_buffer, submission)
create(

View File

@ -15,7 +15,7 @@ class Submission < ApplicationRecord
belongs_to :study_group, optional: true
has_many :testruns
has_many :structured_errors
has_many :structured_errors, dependent: :destroy
has_many :comments, through: :files
belongs_to :external_users, lambda {

View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
class AddForeignKeysToStructuredErrors < ActiveRecord::Migration[7.0]
def change
add_foreign_key :structured_errors, :submissions
add_foreign_key :structured_errors, :error_templates
end
end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class AddForeignKeysAndIndexToStructuredErrorAttributes < ActiveRecord::Migration[7.0]
def change
add_foreign_key :structured_error_attributes, :structured_errors
add_foreign_key :structured_error_attributes, :error_template_attributes
add_index :structured_error_attributes, :structured_error_id
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_03_14_084733) do
ActiveRecord::Schema[7.0].define(version: 2023_03_20_220012) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
enable_extension "pgcrypto"
@ -420,6 +420,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_14_084733) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "match"
t.index ["structured_error_id"], name: "index_structured_error_attributes_on_structured_error_id"
end
create_table "structured_errors", id: :serial, force: :cascade do |t|
@ -600,6 +601,11 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_14_084733) do
add_foreign_key "exercise_tips", "exercises"
add_foreign_key "exercise_tips", "tips"
add_foreign_key "remote_evaluation_mappings", "study_groups"
add_foreign_key "structured_error_attributes", "error_template_attributes"
add_foreign_key "structured_error_attributes", "structured_errors"
add_foreign_key "structured_errors", "error_templates"
add_foreign_key "structured_errors", "error_templates", name: "structured_errors_error_templates_id_fk"
add_foreign_key "structured_errors", "submissions"
add_foreign_key "submissions", "study_groups"
add_foreign_key "subscriptions", "study_groups"
add_foreign_key "testrun_execution_environments", "execution_environments"