2
테이블의 테이블 구조를 변경하고 이전 필드의 값으로 일부 새 필드를 백 필해야합니다. 그래서 마이그레이션을 위해 저장소를 사용하고 싶습니다. 그러나 Hanami가 마이그레이션을 실행할 때로드하지 않으므로 Hanami Model을로드해야합니다.마이그레이션에서 하나미 모델을로드하는 방법은 무엇입니까?
require_relative '../../lib/my_app/repositories/entity_repository'
require_relative '../../lib/my_app/entities/my_entity'
Mutex.new.synchronize do
Hanami::Model.load!
end
Hanami::Model.migration do
change do
def backfill_data!
repo = EntityRepository.new
repo.all.map do |entity|
repo.update entity.id, new_field_as_date: Date.new(entity.old_field)
end
end
backfill_data!
end
end
그러나이 마이그레이션을 실행할 때, 나는
bundler: failed to load command: hanami (/Users/user/.rbenv/versions/2.4.1/bin/hanami)
Hanami::Model::Error: key not found: :person
# which is an association with the entity mentioned on the code
을 얻을 그래서, 지금 어떻게 해야할지 모르겠어요 :
그래서, 지금 나는이 있습니다. 가장 큰 문제는 하나미 마이그레이션에서 데이터를 마이그레이션하는 방법입니다.
답변을 제공해 주신 Luca. 사실, 내가 언급 한 것처럼 SQL을 사용하여 문제를 해결했지만 데이터베이스 드라이버에 대한 Hanami Model 캡슐화를 활용하여 데이터베이스를 인식하지 않는 마이그레이션을 수행 할 것이므로 리포지토리를 사용하는 것이 좋을 것이라고 생각했습니다. 하지만 괜찮아! – rafaels88