Skip to content

Commit

Permalink
Merge pull request #83 from aploshay/POD-1795_serialized_fields
Browse files Browse the repository at this point in the history
[POD-1795] reconfigure serialized fields
  • Loading branch information
aploshay authored Jul 25, 2022
2 parents f578845 + ab21212 commit 1a25209
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
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

0 comments on commit 1a25209

Please sign in to comment.