Class: CaRuby::Migrator
- Inherits:
-
Jinx::Migrator
- Object
- Jinx::Migrator
- CaRuby::Migrator
- Defined in:
- lib/caruby/migration/migrator.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Migrator
constructor
Creates a new Migrator with the given options.
-
#migrate_to_database {|target, row| ... } ⇒ Object
Imports this migrator’s file into the database with the given connect options.
Constructor Details
#initialize(opts = {}) ⇒ Migrator
Creates a new Migrator with the given options.
The migration configuration must provide sufficient information to build a well-formed migration target object. For example, if the target object is a new CaTissue::SpecimenCollectionGroup
, then the migrator must build that SCG’s required CollectionProtocolRegistration
. The CPR in turn must either exist in the database or the migrator must build the required CPR participant
and collection_protocol
.
17 18 19 20 |
# File 'lib/caruby/migration/migrator.rb', line 17 def initialize(opts={}) super @database = opts[:database] end |
Instance Method Details
#migrate_to_database {|target, row| ... } ⇒ Object
Imports this migrator’s file into the database with the given connect options. This method creates or updates the domain objects mapped from the migration source. If a block is given to this method, then the block is called on each migrated target object.
The target object is saved in the database. Every referenced migrated object is created, if necessary. Finally, a migration target owner object is created, if necessary.
For example, suppose a migration configuration specifies the following:
-
the target is a
CaTissue::SpecimenCollectionGroup
-
the field mapping specifies a
Participant
MRN, -
the defaults specify a
CollectionProtocol
title and aSite
name
The migrator attempts to fetch the protocol and site from the database. If they do not exist, then they are created. In order to create the protocol and site, the migration configuration must specify sufficient information to validate the objects before creation, as described in #initialize. Finally, the SCG CollectionProtocolRegistration
owner is created. This CPR references the migration protocol and site.
If the :create
option is set, then an input record for a target object which already exists in the database is noted in a debug log message and ignored rather than updated.
47 48 49 50 51 |
# File 'lib/caruby/migration/migrator.rb', line 47 def migrate_to_database(&block) # migrate with save tm = Jinx::Stopwatch.measure { execute_save(&block) }.elapsed logger.debug { (tm) } end |