This repository provides a practical demonstration of Contentful migrations.
The following initial steps establish the structure for managing your migrations:
-
Create a migrations directory: Establish a directory at your project's root level, where all JavaScript or TypeScript migration scripts will be stored.
-
Order Migration Files: Ensure migration files are organized in an incremental order to maintain version tracking.
-
Develop Migration Running Script: Implement a script to run the migrations.
-
Incorporate GitHub Actions: Utilize GitHub Actions for continuous integration to automate the migration process.
The migration process follows these detailed steps:
-
Create a Migration Branch: Each new migration should be isolated in a separate branch.
-
Implement Migration Runner Script: Develop a script responsible for executing the migrations.
-
Add Migration File: Include your specific migration instructions in a migration file.
-
Export 'master' Environment Data: Preserve the latest 'master' environment content type data from Contentful by exporting and saving it.
-
Create Temporary Contentful Environment: Generate a new Contentful environment as a temporary host during the migration.
-
Import 'master' Environment Data: Load the exported 'master' environment data into the new temporary environment.
-
Run Migrations in Temporary Environment: Execute the migration scripts in the temporary environment.
-
Test the Temporary Environment: Verify the success of migrations and overall system functionality.
-
Merge Migration Branch: Once testing confirms the system's proper behavior, merge the migration branch into the master branch.
-
Execute Migrations on 'master' Branch: Run migrations on the 'master' branch post-merge.
-
Remove Temporary Environment: After successful migration, eliminate the temporary Contentful environment.
-
Manage Version Tracking: The migration script should handle version tracking. To preserve version tracking data, introduce a new Content-type on the Contentful space.
During this proof-of-concept, we evaluated two libraries: contentful-migrate
and contentful-migration
. Although contentful-migrate
required less preliminary work, it has lingering unresolved issues. Consequently, we decided on contentful-migration
for the final implementation.
Note: The preservation of the latest Content Type data from the master environment is crucial due to the lack of rollback support in Contentful.