Commit dcc0f4ce authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Add checksum to ci_job_artifacts

parent d1eb43d584a2
......@@ -6,6 +6,7 @@ class JobArtifact < ActiveRecord::Base
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
before_save :set_size, if: :file_changed?
before_save :set_checksum, if: :file_changed?
mount_uploader :file, JobArtifactUploader
......@@ -25,6 +26,10 @@ def set_size
self.size = file.size
end
def set_checksum
self.checksum = file.checksum
end
def expire_in
expire_at - Time.now if expire_at
end
......
......@@ -9,6 +9,12 @@ def size
model.size
end
def checksum
return calc_checksum if model.checksum.nil?
model.checksum
end
def store_dir
dynamic_segment
end
......@@ -21,6 +27,10 @@ def open
private
def calc_checksum
Digest::SHA256.file(file.path).hexdigest
end
def dynamic_segment
creation_date = model.created_at.utc.strftime('%Y_%m_%d')
......
class AddChecksumToCiJobArtifacts < ActiveRecord::Migration
DOWNTIME = false
def change
add_column :ci_job_artifacts, :checksum, :string, limit: 64
end
end
......@@ -346,6 +346,7 @@
t.datetime_with_timezone "updated_at", null: false
t.datetime_with_timezone "expire_at"
t.string "file"
t.string "checksum", limit: 64
end
add_index "ci_job_artifacts", ["expire_at", "job_id"], name: "index_ci_job_artifacts_on_expire_at_and_job_id", using: :btree
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment