Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate uploaded and generated files
- Loading branch information
1 parent
dc7be05
commit 80612cc
Showing
5 changed files
with
34 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
db/migrate/20131111135126_separate_uploaded_and_generated_files.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class SeparateUploadedAndGeneratedFiles < ActiveRecord::Migration | ||
def up | ||
uploaded_dir, generated_dir = %w{uploaded generated}.collect { |d| File.join(Rails.root, 'files', d) } | ||
|
||
[uploaded_dir, generated_dir].each do |dir| | ||
FileUtils.mkdir_p dir unless File.directory? dir | ||
end | ||
|
||
Datafile.has_attached_file :file, :basename => "basename", :path => ":rails_root/files/:id_:filename" | ||
Dataset.has_attached_file :generated_spreadsheet, :path => ":rails_root/files/:id_generated-download.xls" | ||
|
||
Datafile.where('file_file_name is not NULL and dataset_id is not NULL').find_each do |df| | ||
FileUtils.mv df.file.path, File.join(uploaded_dir, File.basename(df.file.path)) if File.file? df.file.path | ||
end | ||
|
||
Dataset.where('generated_spreadsheet_file_name is not NULL').find_each do |dt| | ||
original_path = dt.generated_spreadsheet.path | ||
FileUtils.mv original_path, File.join(generated_dir, File.basename(original_path)) if File.file? original_path | ||
end | ||
end | ||
|
||
def down | ||
files_dir = File.join(Rails.root, 'files') | ||
|
||
%w{uploaded generated}.each do |dir| | ||
FileUtils.mv Dir.glob(File.join(files_dir, dir, '*.*')), files_dir | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters