Skip to content

Commit

Permalink
refactor: db migration to convert extension weeks to days
Browse files Browse the repository at this point in the history
  • Loading branch information
ublefo committed Apr 30, 2024
1 parent 18cc875 commit fa701a9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
35 changes: 35 additions & 0 deletions db/migrate/20240421011821_change_extension_to_days.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class ChangeExtensionToDays < ActiveRecord::Migration[7.1]
def up
# update extension data in task comments and delete the old column
rename_column :task_comments, :extension_weeks, :extension_days
execute <<~SQL.squish
UPDATE task_comments
SET extension_days = extension_days * 7
WHERE extension_days IS NOT NULL;
SQL

# update extension data in unit settings and delete the old column
rename_column :units, :extension_weeks_on_resubmit_request, :extension_days_on_resubmit_request
execute <<~SQL.squish
UPDATE units
SET extension_days_on_resubmit_request = extension_days_on_resubmit_request * 7;
SQL
end

def down
rename_column :task_comments, :extension_days, :extension_weeks
# anything less than 7 days should be restored to 1 week
execute <<~SQL.squish
UPDATE task_comments
SET extension_weeks = (extension_weeks + 6) / 7
WHERE extension_weeks IS NOT NULL;
SQL

rename_column :units, :extension_days_on_resubmit_request, :extension_weeks_on_resubmit_request
# anything less than 7 days should be restored to 1 week
execute <<~SQL.squish
UPDATE units
SET extension_weeks_on_resubmit_request = (extension_weeks_on_resubmit_request + 6) / 7;
SQL
end
end
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_01_05_055902) do
ActiveRecord::Schema[7.1].define(version: 2024_04_21_011821) do
create_table "activity_types", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t|
t.string "name", null: false
t.string "abbreviation", null: false
Expand Down Expand Up @@ -211,10 +211,10 @@
t.boolean "extension_granted"
t.bigint "assessor_id"
t.bigint "task_status_id"
t.integer "extension_weeks"
t.string "extension_response"
t.bigint "reply_to_id"
t.bigint "overseer_assessment_id"
t.integer "extension_days"
t.index ["assessor_id"], name: "index_task_comments_on_assessor_id"
t.index ["discussion_comment_id"], name: "index_task_comments_on_discussion_comment_id"
t.index ["overseer_assessment_id"], name: "index_task_comments_on_overseer_assessment_id"
Expand Down Expand Up @@ -471,12 +471,12 @@
t.boolean "enable_sync_enrolments", default: true, null: false
t.bigint "draft_task_definition_id"
t.boolean "allow_student_extension_requests", default: true, null: false
t.integer "extension_weeks_on_resubmit_request", default: 1, null: false
t.boolean "allow_student_change_tutorial", default: true, null: false
t.boolean "assessment_enabled", default: true
t.bigint "overseer_image_id"
t.datetime "portfolio_auto_generation_date"
t.string "tii_group_context_id"
t.integer "extension_days_on_resubmit_request", default: 7, null: false
t.index ["draft_task_definition_id"], name: "index_units_on_draft_task_definition_id"
t.index ["main_convenor_id"], name: "index_units_on_main_convenor_id"
t.index ["overseer_image_id"], name: "index_units_on_overseer_image_id"
Expand Down

0 comments on commit fa701a9

Please sign in to comment.