| description | This module provides a framework for importing data into your application from external sources, like an old database or CSV. |
|---|
This module is a Nails orientated wrapper around HelloPablo's Data Migration framework. It exposes console commands for running migrations as well as imposes some structure within Nails applications. Install using Composer:
composer require nails/module-data-migration
There are five key concepts in the data migration module:
Connecters are the classes which "talk" to the data sources. Their purpose is to read and write from a data source (e.g. a CSV file, or a MySQL table).
{% content-ref url="connectors.md" %} connectors.md {% endcontent-ref %}
Pipelines represent a single migration, from a source Connector, to a target Connector. Pipelines define the source and destination Connectors, as well as the Recipe to use when transferring Units of data. They also allow the developer to define a priority, as well as offering hooks at various points throughout the lifecycle of a migration.
{% content-ref url="pipelines.md" %} pipelines.md {% endcontent-ref %}
Recipes deifne how a Unit of data is transformed once it leaves the source Connector, and before it is sent to the target Connector.
{% content-ref url="recipes.md" %} recipes.md {% endcontent-ref %}
Transformers mutate a single piece of data within a Recipe.
{% content-ref url="transformers.md" %} transformers.md {% endcontent-ref %}
Units represent a single item being transferred. A Pipeline transfers multiple units.
{% content-ref url="units.md" %} units.md {% endcontent-ref %}
Run Pipelines using the following console command:
nails datamigration:run
The console accepts no arguments and the following options:
--dry-run Whether to perform a dry-run or not
-f, --filter=FILTER Filter pipelines (only include matches) (multiple values allowed)
-e, --exclude=EXCLUDE Exclude matches (multiple values allowed)
-d, --debug Run in debug mode
-m, --memory=MEMORY Set memory limit (in MB)
-s, --stop-on-error Stop on first error, rather than summarrise
Sometimes it's easier to learn by example.
{% content-ref url="simple-example.md" %} simple-example.md {% endcontent-ref %}