From d3f29d5d72ebb604c09ecff58c890e4743794565 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 20 May 2019 16:35:24 +0200 Subject: [PATCH 1/2] Add type column to zip_exports for STI [SCI-3368] --- app/models/team_zip_export.rb | 15 --------------- app/models/zip_export.rb | 17 ++++++++++++++++- .../20190520135317_add_type_to_zip_exports.rb | 5 +++++ db/schema.rb | 6 +++--- 4 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 db/migrate/20190520135317_add_type_to_zip_exports.rb diff --git a/app/models/team_zip_export.rb b/app/models/team_zip_export.rb index 265723840..742ab5294 100644 --- a/app/models/team_zip_export.rb +++ b/app/models/team_zip_export.rb @@ -7,21 +7,6 @@ require 'csv' class TeamZipExport < ZipExport include StringUtility - # Override path only for S3 - if ENV['PAPERCLIP_STORAGE'] == 's3' - s3_path = - if ENV['S3_SUBFOLDER'] - "/#{ENV['S3_SUBFOLDER']}/zip_exports/:attachment/"\ - ":id_partition/:hash/:style/:filename" - else - '/zip_exports/:attachment/:id_partition/:hash/:style/:filename' - end - - has_attached_file :zip_file, path: s3_path - validates_attachment :zip_file, - content_type: { content_type: 'application/zip' } - end - def generate_exportable_zip(user, data, type, options = {}) @user = user zip_input_dir = FileUtils.mkdir_p( diff --git a/app/models/zip_export.rb b/app/models/zip_export.rb index bc66f59b0..c44590437 100644 --- a/app/models/zip_export.rb +++ b/app/models/zip_export.rb @@ -20,7 +20,22 @@ require 'csv' class ZipExport < ApplicationRecord belongs_to :user, optional: true - has_attached_file :zip_file + + # Override path only for S3 + if ENV['PAPERCLIP_STORAGE'] == 's3' + s3_path = + if ENV['S3_SUBFOLDER'] + "/#{ENV['S3_SUBFOLDER']}/zip_exports/:attachment/"\ + ":id_partition/:hash/:style/:filename" + else + '/zip_exports/:attachment/:id_partition/:hash/:style/:filename' + end + + has_attached_file :zip_file, path: s3_path + else + has_attached_file :zip_file + end + validates_attachment :zip_file, content_type: { content_type: 'application/zip' } diff --git a/db/migrate/20190520135317_add_type_to_zip_exports.rb b/db/migrate/20190520135317_add_type_to_zip_exports.rb new file mode 100644 index 000000000..024a51312 --- /dev/null +++ b/db/migrate/20190520135317_add_type_to_zip_exports.rb @@ -0,0 +1,5 @@ +class AddTypeToZipExports < ActiveRecord::Migration[5.1] + def change + add_column :zip_exports, :type, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index fa4b09ce8..42cf7ba6d 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.define(version: 20190424113216) do +ActiveRecord::Schema.define(version: 20190520135317) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -926,6 +926,7 @@ ActiveRecord::Schema.define(version: 20190424113216) do t.string "zip_file_content_type" t.integer "zip_file_file_size" t.datetime "zip_file_updated_at" + t.string "type" t.index ["user_id"], name: "index_zip_exports_on_user_id" end @@ -1070,7 +1071,7 @@ ActiveRecord::Schema.define(version: 20190424113216) do add_foreign_key "wopi_apps", "wopi_discoveries" add_foreign_key "zip_exports", "users" - create_view "datatables_teams", sql_definition: <<-SQL + create_view "datatables_teams", sql_definition: <<-SQL SELECT teams.id, teams.name, user_teams.role, @@ -1086,5 +1087,4 @@ ActiveRecord::Schema.define(version: 20190424113216) do FROM (teams JOIN user_teams ON ((teams.id = user_teams.team_id))); SQL - end From d46d82d0f065792bf34ae6eebd752b5ec0eb32e9 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 21 May 2019 10:56:55 +0200 Subject: [PATCH 2/2] Fix Hound warning [SCI-3368] --- db/migrate/20190520135317_add_type_to_zip_exports.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20190520135317_add_type_to_zip_exports.rb b/db/migrate/20190520135317_add_type_to_zip_exports.rb index 024a51312..dd22e8b25 100644 --- a/db/migrate/20190520135317_add_type_to_zip_exports.rb +++ b/db/migrate/20190520135317_add_type_to_zip_exports.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddTypeToZipExports < ActiveRecord::Migration[5.1] def change add_column :zip_exports, :type, :string