diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index dac508746..ead9f8dee 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -5,12 +5,12 @@ class UploadsController < ApplicationController skip_before_action :verify_authenticity_token, only: [:create], if: -> { request.xhr? } def new - @upload = authorize Upload.new(uploader: CurrentUser.user, uploader_ip_addr: CurrentUser.ip_addr, rating: "q", tag_string: "", source: params[:url], referer_url: params[:ref], **permitted_attributes(Upload)) + @upload = authorize Upload.new(uploader: CurrentUser.user, uploader_ip_addr: CurrentUser.ip_addr, source: params[:url], referer_url: params[:ref], **permitted_attributes(Upload)) respond_with(@upload) end def create - @upload = authorize Upload.new(uploader: CurrentUser.user, uploader_ip_addr: CurrentUser.ip_addr, rating: "q", tag_string: "", **permitted_attributes(Upload)) + @upload = authorize Upload.new(uploader: CurrentUser.user, uploader_ip_addr: CurrentUser.ip_addr, **permitted_attributes(Upload)) @upload.save respond_with(@upload) end diff --git a/app/models/upload.rb b/app/models/upload.rb index adecf3e83..e870b0ced 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -3,7 +3,12 @@ class Upload < ApplicationRecord extend Memoist - MAX_VIDEO_DURATION = 140 + self.ignored_columns = %i[ + file_path content_type rating tag_string backtrace post_id md5_confirmation + server parent_id md5 file_ext file_size image_width image_height + artist_commentary_desc artist_commentary_title include_artist_commentary + context translated_commentary_title translated_commentary_desc + ] attr_accessor :file @@ -75,7 +80,7 @@ class Upload < ApplicationRecord end def self.search(params) - q = search_attributes(params, :id, :created_at, :updated_at, :source, :referer_url, :uploader, :status, :backtrace, :upload_media_assets, :media_assets) + q = search_attributes(params, :id, :created_at, :updated_at, :source, :referer_url, :status, :uploader, :upload_media_assets, :media_assets) q.apply_default_order(params) end @@ -104,7 +109,7 @@ class Upload < ApplicationRecord media_asset = MediaAsset.upload!(media_file) update!(media_assets: [media_asset], status: "completed") rescue Exception => e - update!(status: "error: #{e.message}", backtrace: e.backtrace.join("\n")) + update!(status: "error: #{e.message}") end def self.available_includes diff --git a/db/migrate/20220203040648_drop_not_null_constraints_from_uploads.rb b/db/migrate/20220203040648_drop_not_null_constraints_from_uploads.rb new file mode 100644 index 000000000..ff387a757 --- /dev/null +++ b/db/migrate/20220203040648_drop_not_null_constraints_from_uploads.rb @@ -0,0 +1,6 @@ +class DropNotNullConstraintsFromUploads < ActiveRecord::Migration[7.0] + def change + change_column_null(:uploads, :rating, true) + change_column_null(:uploads, :tag_string, true) + end +end diff --git a/db/structure.sql b/db/structure.sql index 3589e5e61..5b5bfc48a 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1947,10 +1947,10 @@ CREATE TABLE public.uploads ( source text, file_path character varying, content_type character varying, - rating character(1) NOT NULL, + rating character(1), uploader_id integer NOT NULL, uploader_ip_addr inet NOT NULL, - tag_string text NOT NULL, + tag_string text, status text DEFAULT 'pending'::text NOT NULL, backtrace text, post_id integer, @@ -5775,6 +5775,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220110171023'), ('20220110171024'), ('20220120233850'), -('20220124195900'); +('20220124195900'), +('20220203040648'); diff --git a/test/factories/upload.rb b/test/factories/upload.rb index cee7faa07..e105133a8 100644 --- a/test/factories/upload.rb +++ b/test/factories/upload.rb @@ -2,8 +2,6 @@ FactoryBot.define do factory(:upload) do uploader factory: :user uploader_ip_addr { "127.0.0.1" } - rating { "s" } - tag_string { "" } status { "pending" } source { "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg" }