From 31334cee32b2f8c153e486256ca61c64d03ec521 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Wed, 26 Jun 2024 11:32:28 +0200 Subject: [PATCH] Allow null for saved annotations --- app/models/activity_read_state.rb | 1 + app/models/saved_annotation.rb | 8 ++++---- app/models/submission.rb | 1 + db/schema.rb | 8 +++++--- test/factories/saved_annotations.rb | 4 ++-- test/factories/submissions.rb | 1 + test/models/activity_read_state_test.rb | 1 + test/models/saved_annotation_test.rb | 4 ++-- test/models/submission_test.rb | 1 + 9 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/models/activity_read_state.rb b/app/models/activity_read_state.rb index caa2ae8279..2788f9b48b 100644 --- a/app/models/activity_read_state.rb +++ b/app/models/activity_read_state.rb @@ -8,6 +8,7 @@ # user_id :integer not null # created_at :datetime not null # updated_at :datetime not null +# series_id :integer # class ActivityReadState < ApplicationRecord belongs_to :activity diff --git a/app/models/saved_annotation.rb b/app/models/saved_annotation.rb index ef7cb470f9..d2310a7c61 100644 --- a/app/models/saved_annotation.rb +++ b/app/models/saved_annotation.rb @@ -6,8 +6,8 @@ # title :string(255) not null # annotation_text :text(16777215) # user_id :integer not null -# exercise_id :integer not null -# course_id :integer not null +# exercise_id :integer +# course_id :integer # created_at :datetime not null # updated_at :datetime not null # annotations_count :integer default(0) @@ -17,8 +17,8 @@ class SavedAnnotation < ApplicationRecord validates :annotation_text, presence: true belongs_to :user - belongs_to :exercise - belongs_to :course + belongs_to :exercise, optional: true + belongs_to :course, optional: true has_many :annotations, dependent: :nullify has_many :submissions, through: :annotations diff --git a/app/models/submission.rb b/app/models/submission.rb index f41c91f50a..b8523c80a4 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -14,6 +14,7 @@ # fs_key :string(24) # number :integer # annotated :boolean default(FALSE), not null +# series_id :integer # class Submission < ApplicationRecord diff --git a/db/schema.rb b/db/schema.rb index 56ec0e3916..3eacf5b77b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_03_07_124219) do +ActiveRecord::Schema[7.1].define(version: 2024_06_26_093130) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -82,6 +82,7 @@ t.integer "user_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "series_id" t.index ["activity_id", "course_id", "user_id"], name: "activity_read_states_unique", unique: true t.index ["course_id"], name: "fk_rails_f674cacc14" t.index ["user_id"], name: "fk_rails_96d00253e9" @@ -420,8 +421,8 @@ t.string "title", null: false t.text "annotation_text", size: :medium t.integer "user_id", null: false - t.integer "exercise_id", null: false - t.integer "course_id", null: false + t.integer "exercise_id" + t.integer "course_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "annotations_count", default: 0 @@ -499,6 +500,7 @@ t.string "fs_key", limit: 24 t.integer "number" t.boolean "annotated", default: false, null: false + t.integer "series_id" t.index ["accepted"], name: "index_submissions_on_accepted" t.index ["course_id"], name: "index_submissions_on_course_id" t.index ["exercise_id", "status", "course_id"], name: "ex_st_co_idx" diff --git a/test/factories/saved_annotations.rb b/test/factories/saved_annotations.rb index e637b575ae..f4808e6603 100644 --- a/test/factories/saved_annotations.rb +++ b/test/factories/saved_annotations.rb @@ -6,8 +6,8 @@ # title :string(255) not null # annotation_text :text(16777215) # user_id :integer not null -# exercise_id :integer not null -# course_id :integer not null +# exercise_id :integer +# course_id :integer # created_at :datetime not null # updated_at :datetime not null # annotations_count :integer default(0) diff --git a/test/factories/submissions.rb b/test/factories/submissions.rb index f3a9dc1b71..3fc8ff92f1 100644 --- a/test/factories/submissions.rb +++ b/test/factories/submissions.rb @@ -14,6 +14,7 @@ # fs_key :string(24) # number :integer # annotated :boolean default(FALSE), not null +# series_id :integer # FactoryBot.define do diff --git a/test/models/activity_read_state_test.rb b/test/models/activity_read_state_test.rb index c81a8d69cc..aa5a2e47ae 100644 --- a/test/models/activity_read_state_test.rb +++ b/test/models/activity_read_state_test.rb @@ -8,6 +8,7 @@ # user_id :integer not null # created_at :datetime not null # updated_at :datetime not null +# series_id :integer # require 'test_helper' diff --git a/test/models/saved_annotation_test.rb b/test/models/saved_annotation_test.rb index 48b2ab050a..e4bcb5591b 100644 --- a/test/models/saved_annotation_test.rb +++ b/test/models/saved_annotation_test.rb @@ -6,8 +6,8 @@ # title :string(255) not null # annotation_text :text(16777215) # user_id :integer not null -# exercise_id :integer not null -# course_id :integer not null +# exercise_id :integer +# course_id :integer # created_at :datetime not null # updated_at :datetime not null # annotations_count :integer default(0) diff --git a/test/models/submission_test.rb b/test/models/submission_test.rb index bfa9008e8d..266f26c409 100644 --- a/test/models/submission_test.rb +++ b/test/models/submission_test.rb @@ -14,6 +14,7 @@ # fs_key :string(24) # number :integer # annotated :boolean default(FALSE), not null +# series_id :integer # require 'test_helper'