-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "file" attachment to DataExport model
Migrate previous `DataExport#data` values into `DataExport#file`. Start populating the CSV content into the `DataExport#file` field via the `DataExporter` class calls.
- Loading branch information
1 parent
f92e524
commit e0478de
Showing
7 changed files
with
38 additions
and
4 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
12 changes: 12 additions & 0 deletions
12
app/services/data_migrations/migrate_data_export_data_to_file.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,12 @@ | ||
module DataMigrations | ||
class MigrateDataExportDataToFile | ||
TIMESTAMP = 20240528140244 | ||
MANUAL_RUN = false | ||
|
||
def change | ||
DataExport.find_each do |data_export| | ||
data_export.file.attach(io: CSV.new(data_export.data).to_io, filename: data_export.filename) | ||
end | ||
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
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
16 changes: 16 additions & 0 deletions
16
spec/services/data_migrations/migrate_data_export_data_to_file_spec.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,16 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe DataMigrations::MigrateDataExportDataToFile do | ||
let(:csv_string) { "email_template,send_count\nsign_in_email,1" } | ||
|
||
it "updates all existing DataExport records 'data' fields and puts them into 'file' attachments" do | ||
data_export = create(:data_export, data: csv_string, file: nil) | ||
|
||
described_class.new.change | ||
|
||
data_export.reload | ||
|
||
expect(data_export.file).to be_attached | ||
expect(data_export.file.download).to eq(csv_string) | ||
end | ||
end |