> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognite.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating a data model and mappings

> Step-by-step guide to create a Cognite Core Data Model (CDM) target data model and resource view mappings before you migrate asset-centric resources.

<Warning>
  The migration plugin is an experimental feature. Updates to the Cognite Toolkit are likely to introduce changes to the described commands and processes.
</Warning>

In an asset-centric Cognite Data Fusion (CDF) project, assets, events, time series, and file metadata use fixed schemas. Data modeling lets you define a custom data model that reflects your organizational structure and data relationships.
This guide walks data engineers through creating that data model and mappings from asset-centric resources.

<Steps>
  <Step title="Create a target data model that extends CDM">
    The data model must extend the [CogniteCore model](/cdf/dm/dm_reference/dm_core_data_model). See [Create a data model](#create-a-data-model).
  </Step>

  <Step title="Create resource view mappings">
    Map asset-centric properties to the target views. See [Create resource view mappings](#create-resource-view-mappings).
  </Step>

  <Step title="Deploy the model and mappings">
    Deploy them to your CDF project so the migration plugin can use them. See [Governance](#governance).
  </Step>
</Steps>

## Create a data model

<Note>
  Consider using [Neat](/cdf/deploy/neat) to create your data model. Neat checks your data model for
  consistency and provides insights on how to improve it.
</Note>

The migration plugin requires a target data model for your migration, but it does not prescribe how you create it. The data model must extend the
[CogniteCore model](/cdf/dm/dm_reference/dm_core_data_model) (CDM). That extension connects time series and files to their underlying CDF resources and lets you organize assets into hierarchies.

A typical approach is to start from the CDM schema for assets, time series, files, and events and model unstructured data that lives in metadata fields. For example, the asset-centric Asset resource schema looks like this:

```yaml title="asset_schema.yaml" theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
externalId: string
name: (required) string
parentExternalId: string
metadata: map<string, string>
description: string
dataSetId: integer
source: string
labels: list<label>
geoLocation: geoLocation
```

In the [Kelmarsh](/cdf/deploy/cdf_toolkit/guides/plugins/migration_plugin/example) example, structured values from `metadata` become explicit properties on a `WindTurbine` view:

```yaml title="windturbine.View.yaml" theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
externalId: WindTurbine
space: sp_schema
version: v1
implements:
- externalId: CogniteAsset
  space: cdf_cdm
  type: view
  version: v1
properties:
  parent:
    container:
      externalId: CogniteAsset
      space: cdf_cdm
      type: container
    containerPropertyIdentifier: parent
    # We are overwriting the parent property to update the source
    source:
      type: view
      space: sp_schema
      externalId: KelmarshAsset
      version: v1
  model:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: model # Text type
  country:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: country # Text type
  latitude:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: latitude # Float64 type
  longitude:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: longitude # Float64 type
  manufacturer:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: manufacturer # Text type
  elevationM:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: elevationM # Float64 type
  hubHeightM:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: hubHeightM # Float64 type
  ratedPowerKW:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: ratedPowerKW # Int64 type
  alternativeTitle:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: alternativeTitle # Text type
  rotorDiameterM:
    container:
        externalId: WindTurbine
        space: sp_schema
        type: container
    containerPropertyIdentifier: rotorDiameterM # Int64 type
  commercialOperationsDate:
    container:
      externalId: WindTurbine
      space: sp_schema
      type: container
    containerPropertyIdentifier: commercialOperationsDate # Timestamp type
```

In the same way, create custom views for time series, files, and events as migration targets.

## Create resource view mappings

Create a resource view mapping alongside the data model. The mapping defines how asset-centric properties map to properties in your target views.
The Cognite Toolkit uses these mappings during migration to move data from asset-centric resources into the correct places in your data model, including data type conversion where needed.

These mappings are YAML resources that the Cognite Toolkit can deploy to your CDF project:

```yaml title="windturbine.ResourceViewMapping.yaml" theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
externalId: wind_turbine_mapping
resourceType: asset
viewId:
  space: sp_schema
  externalId: WindTurbine
  version: v1
propertyMapping:
  name: name
  description: description
  source: source # Note that this maps a string to a direct relation
  parentId: parent
  metadata.Model: model
  metadata.Country: country
  metadata.Latitude: latitude
  metadata.Longitude: longitude
  metadata.Manufacturer: manufacturer
  metadata.Elevation (m): elevationM
  metadata.Hub Height (m): hubHeightM
  metadata.Rated power (kW): ratedPowerKW
  metadata.Alternative Title: alternativeTitle
  metadata."Commercial Operations Date": commercialOperationsDate
```

After you create the data model and resource view mapping, deploy them to your CDF project. The migration plugin can then use the deployed model and mappings.

## Governance

See the [Data models](/cdf/deploy/cdf_toolkit/references/resource_library#data-models) and
[Resource view mapping](/cdf/deploy/cdf_toolkit/references/resource_library#resource-view-mapping) sections of the Cognite Toolkit resource library for how to deploy and govern these resources.

## Further reading

* [Deploying the CogniteMigration data model](/cdf/deploy/cdf_toolkit/guides/plugins/migration_plugin/prepare)
* [Kelmarsh example](/cdf/deploy/cdf_toolkit/guides/plugins/migration_plugin/example)
* [Migration overview](/cdf/deploy/cdf_toolkit/guides/plugins/migration_plugin/steps)
