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

Migration scripts run order independent of content type #215

Open gigaSproule opened 3 years ago

gigaSproule commented 3 years ago

Expected Behavior

Run all scripts in date order, regardless of content type.

Actual Behavior

Scripts run in order of content type alphabetical, then by date, causing the migration to fail.

Possible Solution

Instead of going through each folder one by one, get all files under the matching directories and run in order by date.

Steps to Reproduce

  1. Create content model A
  2. Create content model B
  3. Create first file under content model A create some fields
  4. Create first file under content model B create some fields
  5. Create second file under content model B to create a new field and populate it with data from a field in A in a field in B
  6. Create second file under content model A delete field that is now in content model B

Context

We have some spaces that are far behind (or newly created), so need to run through our migration scripts. We have 1 that relies on some field being present in another content type, but another script that deletes that field.

Environment

deluan commented 3 years ago

Sorry for the long delay in replying to this. This folder per content-model structure is a legacy for the original use-case of this tool. There was even work to try to implement a way for it to handle single-folder migrations in the branch https://github.com/deluan/contentful-migrate/tree/single-folder, but this still incomplete.

You don't need to create one folder per content-model. In fact the content-models are not tied to any folder. You can simply have all migrations in one folder by using -t single if you want. This would create a "content-model" folder named single and all your migrations would be in the same folder, independent of what content model they change. This would allow you to run migrations always in sequence, the same behaviour as we have with traditional DB schema migration tools.

Let me know if this solves the issue for you

gigaSproule commented 3 years ago

That's the sort of approach that I have started to migrate to. It would be nice to still have the separate folder structure, so it's easier to go through previous scripts, but at least this works.