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

omeed migrate from large text field: Test out adding migrate_from_large_text_field to Aggregate::Container.store_aggregates_using #158

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
18 changes: 16 additions & 2 deletions lib/aggregate/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,24 @@ def store_aggregates_using_large_text_field
set_callback(:destroy, :before, :decoded_aggregate_store, prepend: true)
end

def store_aggregates_using(storage_field, migrate_from_storage_field: nil)
def store_aggregates_using(storage_field, migrate_from_storage_field: nil, migrate_from_large_text_field: nil)
if migrate_from_storage_field && migrate_from_large_text_field
raise ArgumentError, "migrate_from_storage_field and migrate_from_large_text_field can not be used at the same time"
end

if storage_field == migrate_from_storage_field || storage_field == migrate_from_large_text_field
raise ArgumentError, "storage_field may not be the same as the migration field"
end

raise_if_aggregate_storage_field_already_defined

if migrate_from_large_text_field
include LargeTextField::Owner
large_text_field migrate_from_large_text_field
end

self.aggregate_storage_field = storage_field
self.migrate_from_storage_field = migrate_from_storage_field
self.migrate_from_storage_field = migrate_from_storage_field || migrate_from_large_text_field
set_callback(:save, :before, :write_aggregates)
end

Expand Down