Database Reference
In-Depth Information
In addition to the computational time, a heavy migration requires more work
from the developer. When we are performing a light migration, we pass two
options to Core Data and let the framework do the work. When we perform
a heavy migration, we must explain the migration to Core Data. This requires
us to create a mapping model, configure each entity in the mapping model,
and sometimes even write code specific to a migration. As a result, there is
a significant maintenance cost for the developer on top of the computational
cost. All the same, it's a situation that may arise, so let's take a look at a
heavy migration.
3.4
A Heavy/Manual Migration
A heavy migration is required when we go outside of the bounds of what a
light migration can accomplish. A simple example of something that goes
beyond a light migration is a logic-based migration . Imagine a situation in
which, as part of a migration/application update, we need to change the data
that is in the database. Perhaps there is a typo in the included data or a
change in the logic. Changing the data during the migration is outside of the
scope of a light migration. However, we can easily add it to a heavy migration.
A more complex example would be a situation that involves normalizing data.
In our application, each recipe has one or more recipe ingredients. If we
wanted to expand our application and extract the common parts of the recipe
ingredient into new tables, we would be stepping outside the boundaries of
what a light migration can accomplish.
Creating Our First Mapping Model
In this migration, we are going to accomplish two goals. First we are going to
massage the data during the migration and find every occurrence of Meat or
Fish for the recipe type and replace it with Entrée . In addition, we are going to
create new entities: Ingredient and UnitOfMeasure . During the migration of the
RecipeIngredient entity, we are going to create or associate the appropriate Ingre-
dient to the RecipeIngredient .
The first step is to create a mapping model for this migration. A mapping model
is a description of how the migration is supposed to work. First we create a new
file in Xcode, and select the section for Core Data. In that section, there is a
template called Mapping Model, as shown in Figure 10, Mapping Model template ,
on page 45 . Once we select that template, Xcode asks us to choose the data
model version to use as the source. For this migration, we are going from v2 to
v3, so we select v2. Then Xcode asks us to select the destination model; we'll
select v3. Finally, we must name the mapping model. I named it the very
descriptive FromV2toV3 .
 
 
Search WWH ::




Custom Search