deluan / contentful-migrate

🐎 Schema migration tooling for Contentful, with state management
https://www.contentful.com/blog/2018/09/13/content-model-changes-scale-telus-cms-as-code/
MIT License
60 stars 37 forks source link

Support regular contentful-migrations migration syntax #31

Open deluan opened 5 years ago

deluan commented 5 years ago

This tool should be able to run scripts meant to be used directly by Contentful's migration tool, i.e. without up and down, only exporting a function.

It could auto-detect that the migrations file is exporting a single function, and consider that as a up, creating a dynamic no-op down, and a auto-generated description (based on the file name.

As an example, a script like this (from Contentful's migration tool README:

module.exports = function (migration, context) {
  const dog = migration.createContentType('dog');
  const name = dog.createField('name');
  name.type('Symbol').required(true);
};

would be behave as if it was something like this:

module.exports.description = <filename>;

module.exports.up = (migration, context) => {
  const dog = migration.createContentType('dog');
  const name = dog.createField('name');
  name.type('Symbol').required(true);
};

module.exports.down = () => throw new Error('down migration is not available");