Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POD-1795] reconfigure serialized fields #83

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/digital_status.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class DigitalStatus < ActiveRecord::Base
require 'json/ext'

serialize :options, Hash
serialize :options, JSON
belongs_to :physical_object
validates :physical_object, presence: true
validates :physical_object_mdpi_barcode, presence: true
before_validation :set_mdpi_barcode_from_object

DIGITAL_STATUS_START = "transferred"
serialized_empty_hash = "--- {}\n"
serialized_empty_hash = {}.to_json.to_s
# the number of hours after digitization start that a video physical object is auto-accepted
@@Video_File_Auto_Accept = TechnicalMetadatumModule::GENRE_AUTO_ACCEPT_DAYS[:video] * 24
# the number of hours after digitization start that an audio physical object is auto-accepted
Expand Down
2 changes: 1 addition & 1 deletion app/models/memnon_invoice_submission.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MemnonInvoiceSubmission < ActiveRecord::Base
serialize :problems_by_row
serialize :problems_by_row, JSON
validates :filename, presence: true
end
10 changes: 10 additions & 0 deletions db/migrate/20220719160322_add_serialized_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddSerializedFields < ActiveRecord::Migration
def up
add_column :memnon_invoice_submissions, :problems_by_row_json, :text, limit: 4294967295
add_column :digital_statuses, :options_json, :text, limit: 65535
end
def down
remove_column :memnon_invoice_submissions, :problems_by_row_json
remove_column :digital_statuses, :options_json
end
end
25 changes: 25 additions & 0 deletions db/migrate/20220721194158_populate_serialized_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class PopulateSerializedFields < ActiveRecord::Migration
def up
puts "Populating MemnonInvoiceSubmission: #{MemnonInvoiceSubmission.count}"
MemnonInvoiceSubmission.find_in_batches.with_index do |group, batch|
puts "processing batch #{batch}"
group.each_with_index do |mis, i|
puts "#{i+1}: #{mis.id}"
mis.problems_by_row_json = mis.problems_by_row
mis.save!
end
end
puts "Populating DigitalStatus: #{DigitalStatus.count}"
DigitalStatus.find_in_batches.with_index do |group, batch|
puts "processing batch #{batch}"
group.each_with_index do |ds, i|
puts "#{i+1}: #{ds.id}"
ds.options_json = ds.options
ds.save!
end
end
end
def down
puts "no action on rollback"
end
end
14 changes: 14 additions & 0 deletions db/migrate/20220721194740_rename_serialized_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class RenameSerializedFields < ActiveRecord::Migration
def up
rename_column :memnon_invoice_submissions, :problems_by_row, :problems_by_row_yaml
rename_column :memnon_invoice_submissions, :problems_by_row_json, :problems_by_row
rename_column :digital_statuses, :options, :options_yaml
rename_column :digital_statuses, :options_json, :options
end
def down
rename_column :memnon_invoice_submissions, :problems_by_row, :problems_by_row_json
rename_column :memnon_invoice_submissions, :problems_by_row_yaml, :problems_by_row
rename_column :digital_statuses, :options, :options_json
rename_column :digital_statuses, :options_yaml, :options
end
end