From d2a089d057706f888d814c4ac2d66a50900f48dc Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Mon, 3 Jul 2017 10:09:48 +0200 Subject: [PATCH] Add structured errors to schema --- app/models/error_template.rb | 3 ++ app/models/error_template_attribute.rb | 3 ++ app/models/structured_error.rb | 4 +++ app/models/structured_error_attribute.rb | 4 +++ .../20170703075832_create_error_templates.rb | 11 +++++++ ...075959_create_error_template_attributes.rb | 11 +++++++ ...20170703080205_create_structured_errors.rb | 10 ++++++ ...0355_create_structured_error_attributes.rb | 11 +++++++ db/schema.rb | 33 ++++++++++++++++++- test/factories/error_template_attributes.rb | 7 ++++ test/factories/error_templates.rb | 7 ++++ test/factories/structured_error_attributes.rb | 7 ++++ test/factories/structured_errors.rb | 6 ++++ test/models/error_template_attribute_test.rb | 7 ++++ test/models/error_template_test.rb | 7 ++++ .../models/structured_error_attribute_test.rb | 7 ++++ test/models/structured_error_test.rb | 7 ++++ 17 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 app/models/error_template.rb create mode 100644 app/models/error_template_attribute.rb create mode 100644 app/models/structured_error.rb create mode 100644 app/models/structured_error_attribute.rb create mode 100644 db/migrate/20170703075832_create_error_templates.rb create mode 100644 db/migrate/20170703075959_create_error_template_attributes.rb create mode 100644 db/migrate/20170703080205_create_structured_errors.rb create mode 100644 db/migrate/20170703080355_create_structured_error_attributes.rb create mode 100644 test/factories/error_template_attributes.rb create mode 100644 test/factories/error_templates.rb create mode 100644 test/factories/structured_error_attributes.rb create mode 100644 test/factories/structured_errors.rb create mode 100644 test/models/error_template_attribute_test.rb create mode 100644 test/models/error_template_test.rb create mode 100644 test/models/structured_error_attribute_test.rb create mode 100644 test/models/structured_error_test.rb diff --git a/app/models/error_template.rb b/app/models/error_template.rb new file mode 100644 index 00000000..9b441d51 --- /dev/null +++ b/app/models/error_template.rb @@ -0,0 +1,3 @@ +class ErrorTemplate < ActiveRecord::Base + belongs_to :execution_environment +end diff --git a/app/models/error_template_attribute.rb b/app/models/error_template_attribute.rb new file mode 100644 index 00000000..361b727b --- /dev/null +++ b/app/models/error_template_attribute.rb @@ -0,0 +1,3 @@ +class ErrorTemplateAttribute < ActiveRecord::Base + belongs_to :error_template +end diff --git a/app/models/structured_error.rb b/app/models/structured_error.rb new file mode 100644 index 00000000..46f40423 --- /dev/null +++ b/app/models/structured_error.rb @@ -0,0 +1,4 @@ +class StructuredError < ActiveRecord::Base + belongs_to :error_template + belongs_to :file, class_name: 'CodeOcean::File' +end diff --git a/app/models/structured_error_attribute.rb b/app/models/structured_error_attribute.rb new file mode 100644 index 00000000..335a5901 --- /dev/null +++ b/app/models/structured_error_attribute.rb @@ -0,0 +1,4 @@ +class StructuredErrorAttribute < ActiveRecord::Base + belongs_to :structured_error + belongs_to :error_template_attribute +end diff --git a/db/migrate/20170703075832_create_error_templates.rb b/db/migrate/20170703075832_create_error_templates.rb new file mode 100644 index 00000000..6f442842 --- /dev/null +++ b/db/migrate/20170703075832_create_error_templates.rb @@ -0,0 +1,11 @@ +class CreateErrorTemplates < ActiveRecord::Migration + def change + create_table :error_templates do |t| + t.belongs_to :execution_environment + t.string :name + t.string :signature + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20170703075959_create_error_template_attributes.rb b/db/migrate/20170703075959_create_error_template_attributes.rb new file mode 100644 index 00000000..3503fcac --- /dev/null +++ b/db/migrate/20170703075959_create_error_template_attributes.rb @@ -0,0 +1,11 @@ +class CreateErrorTemplateAttributes < ActiveRecord::Migration + def change + create_table :error_template_attributes do |t| + t.belongs_to :error_template + t.string :key + t.string :regex + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20170703080205_create_structured_errors.rb b/db/migrate/20170703080205_create_structured_errors.rb new file mode 100644 index 00000000..560649b4 --- /dev/null +++ b/db/migrate/20170703080205_create_structured_errors.rb @@ -0,0 +1,10 @@ +class CreateStructuredErrors < ActiveRecord::Migration + def change + create_table :structured_errors do |t| + t.references :error_template + t.belongs_to :file + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20170703080355_create_structured_error_attributes.rb b/db/migrate/20170703080355_create_structured_error_attributes.rb new file mode 100644 index 00000000..aa9ee04e --- /dev/null +++ b/db/migrate/20170703080355_create_structured_error_attributes.rb @@ -0,0 +1,11 @@ +class CreateStructuredErrorAttributes < ActiveRecord::Migration + def change + create_table :structured_error_attributes do |t| + t.belongs_to :structured_error + t.references :error_template_attribute + t.string :value + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 81693c1d..6e12f864 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: 20170608141612) do +ActiveRecord::Schema.define(version: 20170703080355) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -47,6 +47,22 @@ ActiveRecord::Schema.define(version: 20170608141612) do t.string "oauth_secret", limit: 255 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 + end + + create_table "error_templates", force: :cascade do |t| + t.integer "execution_environment_id" + t.string "name" + t.string "signature" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "errors", force: :cascade do |t| t.integer "execution_environment_id" t.text "message" @@ -268,6 +284,21 @@ ActiveRecord::Schema.define(version: 20170608141612) do t.datetime "updated_at" end + create_table "structured_error_attributes", force: :cascade do |t| + t.integer "structured_error_id" + t.integer "error_template_attribute_id" + t.string "value" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "structured_errors", force: :cascade do |t| + t.integer "error_template_id" + t.integer "file_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "submissions", force: :cascade do |t| t.integer "exercise_id" t.float "score" diff --git a/test/factories/error_template_attributes.rb b/test/factories/error_template_attributes.rb new file mode 100644 index 00000000..24adb856 --- /dev/null +++ b/test/factories/error_template_attributes.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :error_template_attribute do + error_template nil + key "MyString" + regex "MyString" + end +end diff --git a/test/factories/error_templates.rb b/test/factories/error_templates.rb new file mode 100644 index 00000000..2abf68c9 --- /dev/null +++ b/test/factories/error_templates.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :error_template do + execution_environment nil + name "MyString" + signature "MyString" + end +end diff --git a/test/factories/structured_error_attributes.rb b/test/factories/structured_error_attributes.rb new file mode 100644 index 00000000..7485967c --- /dev/null +++ b/test/factories/structured_error_attributes.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :structured_error_attribute do + structured_error nil + error_template_attribute nil + value "MyString" + end +end diff --git a/test/factories/structured_errors.rb b/test/factories/structured_errors.rb new file mode 100644 index 00000000..4a87cec1 --- /dev/null +++ b/test/factories/structured_errors.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :structured_error do + error_template nil + file nil + end +end diff --git a/test/models/error_template_attribute_test.rb b/test/models/error_template_attribute_test.rb new file mode 100644 index 00000000..187ae1b7 --- /dev/null +++ b/test/models/error_template_attribute_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ErrorTemplateAttributeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/error_template_test.rb b/test/models/error_template_test.rb new file mode 100644 index 00000000..538dc19a --- /dev/null +++ b/test/models/error_template_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ErrorTemplateTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/structured_error_attribute_test.rb b/test/models/structured_error_attribute_test.rb new file mode 100644 index 00000000..1dcb316b --- /dev/null +++ b/test/models/structured_error_attribute_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class StructuredErrorAttributeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/structured_error_test.rb b/test/models/structured_error_test.rb new file mode 100644 index 00000000..28b03689 --- /dev/null +++ b/test/models/structured_error_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class StructuredErrorTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end