Completely remove old non-structured errors and migrate existing ones.
This commit is contained in:
46
db/migrate/20181129093207_drop_errors.rb
Normal file
46
db/migrate/20181129093207_drop_errors.rb
Normal file
@ -0,0 +1,46 @@
|
||||
class DropErrors < ActiveRecord::Migration[5.2]
|
||||
|
||||
# define old CodeOcean::Error module so that the migration works
|
||||
module CodeOcean
|
||||
class Error < ApplicationRecord
|
||||
belongs_to :execution_environment
|
||||
|
||||
scope :for_execution_environment, ->(execution_environment) { where(execution_environment_id: execution_environment.id) }
|
||||
scope :grouped_by_message, -> { select('MAX(created_at) AS created_at, MAX(id) AS id, message, COUNT(id) AS count').group(:message).order('count DESC') }
|
||||
|
||||
validates :execution_environment_id, presence: true
|
||||
validates :message, presence: true
|
||||
|
||||
def self.nested_resource?
|
||||
true
|
||||
end
|
||||
|
||||
def to_s
|
||||
id.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def change
|
||||
|
||||
puts 'Migrating CodeOcean::Errors to StructuredErrors using RegEx. This might take a (long) while but will return.'
|
||||
submissions_controller = SubmissionsController.new
|
||||
|
||||
# Iterate only over those Errors containing a message and submission_id
|
||||
CodeOcean::Error.where.not(message: [nil, ""]).where.not(submission_id: [nil, ""]).each do |error|
|
||||
raw_output = error.message
|
||||
submission = Submission.find_by(id: error.submission_id)
|
||||
|
||||
# Validate that we have everything we need: the output, the submission and the execution environment
|
||||
next if submission.exercise.execution_environment.blank?
|
||||
|
||||
submissions_controller.instance_variable_set(:@raw_output, raw_output)
|
||||
submissions_controller.instance_variable_set(:@submission, submission)
|
||||
submissions_controller.extract_errors
|
||||
end
|
||||
|
||||
drop_table :errors
|
||||
end
|
||||
end
|
11
db/schema.rb
11
db/schema.rb
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_11_27_160857) do
|
||||
ActiveRecord::Schema.define(version: 2018_11_29_093207) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -81,15 +81,6 @@ ActiveRecord::Schema.define(version: 2018_11_27_160857) do
|
||||
t.text "hint"
|
||||
end
|
||||
|
||||
create_table "errors", force: :cascade do |t|
|
||||
t.integer "execution_environment_id"
|
||||
t.text "message"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "submission_id"
|
||||
t.index ["submission_id"], name: "index_errors_on_submission_id"
|
||||
end
|
||||
|
||||
create_table "events", force: :cascade do |t|
|
||||
t.string "category"
|
||||
t.string "data"
|
||||
|
@ -10,9 +10,6 @@ Rails.application.routes.default_url_options = Rails.application.config.action_m
|
||||
# execution environments
|
||||
ExecutionEnvironment.create_factories
|
||||
|
||||
# errors
|
||||
CodeOcean::Error.create_factories
|
||||
|
||||
# exercises
|
||||
@exercises = find_factories_by_class(Exercise).map(&:name).map { |factory_name| [factory_name, FactoryBot.create(factory_name)] }.to_h
|
||||
|
||||
|
Reference in New Issue
Block a user