Migration script to migrate media

Is there a way to make DatoCMS migration script for migrating media from one environment to another environment? If yes can you provide a sample code?

I have a few more additional questions.

  1. Are the source media files shared between the fork and source environment?
  2. Does all the newly added media files in the forked environment get deleted when the fork is deleted?

Hey @saran,

Unfortunately we don’t provide an automatic script for that, but you can use the Content Management API with our JS client in a script. You’d list and retrieve them from one environment, then upload them to the other.

  1. Are the source media files shared between the fork and source environment?

EDIT: Yes, they are shared, but we don’t delete the media unless there are zero environments using it.

(This is wrong!) No, they’re separate. When you fork an environment we copy those assets over but they otherwise have individual lives.

  1. Does all the newly added media files in the forked environment get deleted when the fork is deleted?

If no environments are using the asset anymore, it will get deleted from within ~24 hours, but might take a bit of time to propagate across the CDN.

If another environment is still using the same asset, it will remain until no environments reference it any longer.

@saran,

I apologize, I made a mistake in my previous post! I was informed that actually, asset references ARE shared between environments.

When you upload an image, it gets saved to our S3 bucket.

If you then fork an environment, the new environment will use that same file on disk. If you then delete it from the fork (or delete the whole fork), the actual asset file will still be there because the original environment still references it.

Once all references are removed (i.e. the media isn’t used in any environments anymore), then it will be deleted within ~24 hours.

Sorry about that!

@roger Thanks for the udpate

1 Like