npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@becklyn/contentful-migrations

v0.1.1

Published

A tool for executing content model migrations in Contentful

Downloads

8

Readme

Becklyn Contentful Migrations

A tool for managing content model migrations for Contentful. Inspired by the "Integrating migrations in a continuous delivery pipeline with CircleCI" article and Doctrine Migrations, based on examples from
contentful-labs/continous-delivery-environments-example.

Introduction

The tool can run migrations on both production-type environments which need to be stable and supporting rollbacks, as well as on temporary feature environments. To do the former, you need to have environment aliases enabled in your Contentful space.

For production-type environments, it creates a copy of the master environment, applies migrations, and switches the alias to point at the freshly migrated environment. The original environment is still available in case a rollback is needed.

For temporary environments it checks if the environment already exists, deletes it if it does, creates it as a copy of master and applies migrations. This is intended for environments working with feature branches of applications.

A third type of environment is supported as well: a permanent, non-aliased environment where there is no need for rollbacks. These are treated similar to temporary environments, but the environment is not deleted and recreated from master if it already exists before migrations are applied. This is intended for staging, QA or similar environments.

Writing migrations

Read the official Contentful tutorial.

Contentful setup

To track which migrations have been applied to an environment, the tool requires a migrationVersions content model to be manually created in the environment. It needs to have two fields: version (short text) and executedAt (date & time). The name and field id of those fields need to be the same.

Installation

Globally

npm install -g @becklyn/contentful-migrations

Locally

npm install --save-dev @becklyn/contentful-migrations

Usage

Global installation

becklyn-contentful-migrate <args>

Local installation

npx becklyn-contentful-migrate <args>

Arguments

becklyn-contentful-migrate <space_id> <environment> <cma_access_token> [migrations_dir] [config_file]
  • space_id: The id of the Contentful space to run migrations on. If you open Contentful, your url will be something like https://app.contentful.com/spaces/a1ht3vblaj8x/...; in this case, a1ht3vblaj8x is your space id.
  • environment: The name of the environment on which to execute migrations on.
  • cma_access_token: You need to create a CMA access token in your space to execute migrations, and pass it to the command.
  • migrations_dir: Path to the folder where your migrations are stored. Defaults to migrations.
  • config_file: Path to the migrations configuration file. Defaults to contentful_migrations.json.

Configuration

The configuration file is a json file with the following structure:

{
  "environments": [
    {
      "environment": "master",
      "alias": true,
      "persistent": false
    },
    {
      "environment": "foo",
      "alias": false,
      "persistent": false
    },
    ...
  ]
}

For each environment, two configuration properties are available:

  • alias: Set to true if the environment is aliased, in other words if it should be treated as a production-type environment as described in the introduction. If set to true, persistent is ignored.
  • persistent: Only relevant if alias is set to false. If false, the environment will be deleted and recreated from master before migrations are executed. If true, it migrations will be applied to it without deletion/recreation.

The default configuration for environments named master, staging and integration have alias set to true, while for all other environments both alias and persistent are set to false. Use the configuration file to override this behavior.

Examples

The examples folder contains examples of migrations, initial content they can be applied to, and a configuration file.