0

I'm migrating an ancient blog from PostgreSQL to Contentful. I'd like to use data from the old blog posts to fill in Contentful entries' sys.createdAt, sys.updatedAt, sys.publishedAt, and sys.firstPublishedAt.

I've read through:

Didn't find anything.

I've read a couple of examples where people create their own publishedAt field in a content type rather than add to sys date properties.

I tried to replicate the data structure of exported content as exported by contentful-cli and filled in the date properties with my own data:

// I edited these dates
"createdAt": "2020-09-05T13:14:00.768Z",
"updatedAt": "2021-06-05T13:14:20.303Z",
...
"publishedAt": "2021-06-05T13:14:20.303Z",
"firstPublishedAt": "2020-10-05T13:14:20.303Z",

Then I imported the JSON file with the same CLI. This did not work.

I also tried importing a file exported with contentful space export with no custom edits in it. It turns out, Contentful always uses the time of import for all entry date properties regardless of the dates in the exported file.

It says somewhere in relation to the Content Delivery API that we can't edit sys. But I've not seen it explicitly stated that we can't do it with the CMA or the migration tools. Is it really not possible to add those details for the purpose of migration?

nusantara
  • 1,109
  • 1
  • 15
  • 38

1 Answers1

0

Contentful DevRel here.

You're correct. The sys object contains system-managed metadata and its fields can not be changed programmatically. It doesn't matter if you use the official tooling.

(The only exception is that you can specify sys.id on entry creation.)

I've read a couple of examples where people create their own publishedAt field in a content type rather than add to sys date properties.

That is the recommended way to go. For any data you want to control, create new fields and manage them however you like.

stefan judis
  • 3,416
  • 14
  • 22
  • Can I just check my understanding then. I'm trying to migrate content from WP to Contentful and would like to retain the author and created/published/updated date information but you're saying it's not possible to do that with the inbuilt sys data and instead new fields would need to be added to the blog entry itself to store and reference that data? – ashleytwo Jul 27 '23 at 12:53
  • 1
    Correct. Publish date should be it's own field. Because `sys.createdAt` will be the time you create the entry in Contentful. `updatedAt` could rely on `sys.updatedAt` though because a person hitting publish probably doesn't want to switch a date field and the last publish / update time is reflected in `sys.updatedAt`. :) – stefan judis Jul 27 '23 at 16:29
  • Ah that's a pain. Is there any way of setting a date field default value to today's date? Ideally I'd populate that field through the POST request for existing content but then have it default for new content so they're not having to populate that field as it would essentially be duplication for entries created via the CMS. Thanks for the swift response btw. – ashleytwo Jul 27 '23 at 17:03
  • If you're migrating over you'd be in control of default values via a script. But please open another question to no derail the topic here. :) – stefan judis Jul 27 '23 at 22:20
  • Nah I was talking about new content (post migration) but will do. Thanks again. – ashleytwo Jul 28 '23 at 12:51