From 6809e82dab8760040170a4afac87c06457be88ac Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Wed, 10 Apr 2024 16:13:02 +0100 Subject: [PATCH] Don't set a default upload filename We don't need a default on this field as it'll be set when it's created. --- app/models/upload.rb | 2 +- ...40410151207_change_upload_filename_default.rb | 5 +++++ db/schema.rb | 4 ++-- lib/tasks/uploads.rake | 13 ------------- spec/factories/uploads.rb | 2 +- spec/fixtures/files/translation_upload.pdf | Bin 1106 -> 0 bytes spec/models/upload_spec.rb | 2 +- 7 files changed, 10 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20240410151207_change_upload_filename_default.rb delete mode 100644 lib/tasks/uploads.rake delete mode 100644 spec/fixtures/files/translation_upload.pdf diff --git a/app/models/upload.rb b/app/models/upload.rb index 99d811ddd7..ba6ab75225 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -3,7 +3,7 @@ # Table name: uploads # # id :bigint not null, primary key -# filename :string default(""), not null +# filename :string not null # malware_scan_result :string default("pending"), not null # translation :boolean not null # created_at :datetime not null diff --git a/db/migrate/20240410151207_change_upload_filename_default.rb b/db/migrate/20240410151207_change_upload_filename_default.rb new file mode 100644 index 0000000000..5bbfa1c01a --- /dev/null +++ b/db/migrate/20240410151207_change_upload_filename_default.rb @@ -0,0 +1,5 @@ +class ChangeUploadFilenameDefault < ActiveRecord::Migration[7.1] + def change + change_column_default :uploads, :filename, from: "", to: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index f6626d5cc2..133d9394f3 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_04_10_150439) do +ActiveRecord::Schema[7.1].define(version: 2024_04_10_151207) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -533,7 +533,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "malware_scan_result", default: "pending", null: false - t.string "filename", default: "", null: false + t.string "filename", null: false t.index ["document_id"], name: "index_uploads_on_document_id" end diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake deleted file mode 100644 index 8713e8fc6d..0000000000 --- a/lib/tasks/uploads.rake +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -namespace :uploads do - desc "Resend blob data for uploads that have a pending malware scan result" - task update_filename: :environment do - Upload - .where(filename: "") - .with_attached_attachment - .find_each do |upload| - upload.update!(filename: upload.attachment.filename || "unknown") - end - end -end diff --git a/spec/factories/uploads.rb b/spec/factories/uploads.rb index 7291738236..016b1fe764 100644 --- a/spec/factories/uploads.rb +++ b/spec/factories/uploads.rb @@ -3,7 +3,7 @@ # Table name: uploads # # id :bigint not null, primary key -# filename :string default(""), not null +# filename :string not null # malware_scan_result :string default("pending"), not null # translation :boolean not null # created_at :datetime not null diff --git a/spec/fixtures/files/translation_upload.pdf b/spec/fixtures/files/translation_upload.pdf deleted file mode 100644 index 232fb40e3e41801b765c7c127e546eda75f7dc34..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1106 zcmah|&2G~`5N;(7XrE#(5kZJ#f8swBMS_GN1W`j02}G5HW3N-A)LX4LQs~og<3%dY zyaTE@aDx|MHn!v9RAOb>yWh;td^7X8H64wgvW_6Fo7>;FzrOzY^8Mx;=>Y|``b7GD z=)RTN+FXEx&IBqJ3|7z{{mvElG6Z_S0$$gVhI&*N=`vatoAd5B^$)@~V8=Tv1Q)D*$)?!k$Q?HS5* z-J+eA38BCQp@#*o;|K>5s4&OFY1#$Z0b?8`*uc1plp7f3NTGo-ilb~`oMSx=OgLCm z1M4A+BkZ2LJ^$FxxhJn9?&L5!OgB>Rf7N+(q5=88OQG`Ipzikba05nKt(RwG@)!D~9&-Qy diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 9e4106ae9e..f1d067c4b9 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -3,7 +3,7 @@ # Table name: uploads # # id :bigint not null, primary key -# filename :string default(""), not null +# filename :string not null # malware_scan_result :string default("pending"), not null # translation :boolean not null # created_at :datetime not null