From 872611bff64e624c5105fb526d16248297f0cd92 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Tue, 11 Jul 2017 19:22:12 +0200 Subject: [PATCH] Update schema to reflect re-usable error_template_attributes, descriptions, hints, and sorting --- app/models/error_template.rb | 1 + app/models/error_template_attribute.rb | 2 +- app/models/execution_environment.rb | 1 + ...add_description_and_hint_to_error_template.rb | 9 +++++++++ ..._template_attribute_relationship_to_n_to_m.rb | 6 ++++++ db/schema.rb | 16 ++++++++++++---- 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20170711170456_add_description_and_hint_to_error_template.rb create mode 100644 db/migrate/20170711170928_change_error_template_attribute_relationship_to_n_to_m.rb diff --git a/app/models/error_template.rb b/app/models/error_template.rb index 9b441d51..dc497d48 100644 --- a/app/models/error_template.rb +++ b/app/models/error_template.rb @@ -1,3 +1,4 @@ class ErrorTemplate < ActiveRecord::Base belongs_to :execution_environment + has_and_belongs_to_many :error_template_attributes end diff --git a/app/models/error_template_attribute.rb b/app/models/error_template_attribute.rb index 361b727b..15229b33 100644 --- a/app/models/error_template_attribute.rb +++ b/app/models/error_template_attribute.rb @@ -1,3 +1,3 @@ class ErrorTemplateAttribute < ActiveRecord::Base - belongs_to :error_template + has_and_belongs_to_many :error_template end diff --git a/app/models/execution_environment.rb b/app/models/execution_environment.rb index 3a4efdde..74177173 100644 --- a/app/models/execution_environment.rb +++ b/app/models/execution_environment.rb @@ -11,6 +11,7 @@ class ExecutionEnvironment < ActiveRecord::Base has_many :exercises belongs_to :file_type has_many :hints + has_many :error_templates scope :with_exercises, -> { where('id IN (SELECT execution_environment_id FROM exercises)') } diff --git a/db/migrate/20170711170456_add_description_and_hint_to_error_template.rb b/db/migrate/20170711170456_add_description_and_hint_to_error_template.rb new file mode 100644 index 00000000..62cbee95 --- /dev/null +++ b/db/migrate/20170711170456_add_description_and_hint_to_error_template.rb @@ -0,0 +1,9 @@ +class AddDescriptionAndHintToErrorTemplate < ActiveRecord::Migration + def change + add_column :error_templates, :description, :text + add_column :error_templates, :hint, :text + + add_column :error_template_attributes, :description, :text + add_column :error_template_attributes, :important, :boolean + end +end diff --git a/db/migrate/20170711170928_change_error_template_attribute_relationship_to_n_to_m.rb b/db/migrate/20170711170928_change_error_template_attribute_relationship_to_n_to_m.rb new file mode 100644 index 00000000..d10fbda2 --- /dev/null +++ b/db/migrate/20170711170928_change_error_template_attribute_relationship_to_n_to_m.rb @@ -0,0 +1,6 @@ +class ChangeErrorTemplateAttributeRelationshipToNToM < ActiveRecord::Migration + def change + remove_belongs_to :error_template_attributes, :error_template + create_join_table :error_templates, :error_template_attributes + end +end diff --git a/db/schema.rb b/db/schema.rb index 6e12f864..137d251d 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: 20170703080355) do +ActiveRecord::Schema.define(version: 20170711170928) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -48,11 +48,17 @@ ActiveRecord::Schema.define(version: 20170703080355) do end create_table "error_template_attributes", force: :cascade do |t| - t.integer "error_template_id" t.string "key" t.string "regex" - 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.text "description" + t.boolean "important" + end + + create_table "error_template_attributes_templates", id: false, force: :cascade do |t| + t.integer "error_template_id", null: false + t.integer "error_template_attribute_id", null: false end create_table "error_templates", force: :cascade do |t| @@ -61,6 +67,8 @@ ActiveRecord::Schema.define(version: 20170703080355) do t.string "signature" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.text "description" + t.text "hint" end create_table "errors", force: :cascade do |t|