Skip to content

Commit fd7d39f

Browse files
committed
(chore) Add timestamps to Submission and SubmissionFile models
Because we're using UUIDs instead of sequential IDs, it's hard to tell what the *last* submission is. Adding timestamps will make this possible.
1 parent 7e53d51 commit fd7d39f

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class AddMissingTimestamps < ActiveRecord::Migration[5.2]
2+
def change
3+
# from: https://stackoverflow.com/questions/46520907/add-timestamps-to-existing-table-in-db-rails-5?rq=1
4+
# add new column but allow null values
5+
add_timestamps :submissions, null: true
6+
add_timestamps :submission_files, null: true
7+
8+
# backfill existing record with created_at and updated_at
9+
# values making clear that the records are faked
10+
long_ago = DateTime.new(2000, 1, 1)
11+
Submission.update_all(created_at: long_ago, updated_at: long_ago)
12+
SubmissionFile.update_all(created_at: long_ago, updated_at: long_ago)
13+
14+
# change not null constraints
15+
change_column_null :submissions, :created_at, false
16+
change_column_null :submissions, :updated_at, false
17+
change_column_null :submission_files, :created_at, false
18+
change_column_null :submission_files, :updated_at, false
19+
end
20+
end

db/schema.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2018_07_06_003625) do
13+
ActiveRecord::Schema.define(version: 2018_07_27_170406) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "pgcrypto"
@@ -81,6 +81,8 @@
8181
create_table "submission_files", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
8282
t.uuid "submission_id", null: false
8383
t.integer "rows"
84+
t.datetime "created_at", null: false
85+
t.datetime "updated_at", null: false
8486
t.index ["submission_id"], name: "index_submission_files_on_submission_id"
8587
end
8688

@@ -90,6 +92,8 @@
9092
t.integer "levy"
9193
t.string "aasm_state"
9294
t.uuid "task_id"
95+
t.datetime "created_at", null: false
96+
t.datetime "updated_at", null: false
9397
t.index ["aasm_state"], name: "index_submissions_on_aasm_state"
9498
t.index ["framework_id"], name: "index_submissions_on_framework_id"
9599
t.index ["supplier_id"], name: "index_submissions_on_supplier_id"

0 commit comments

Comments
 (0)