Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Migrate from KeystoneJS v4 (Keystone Classic)

default discord avatar
joephuz.2 years ago
9

Ive got a number of older sites running keystone v4... Lately been wondering if i'ts possible to migrate these over to Payload. Seems doable, but does anybody have any insight to how challenging/possible this would be or have any ideas, pointers, experience doing something similar?

  • discord user avatar
    denolfe
    2 years ago

    I haven't used keystone for quite some time, but really what this comes down to is massaging data from keystone into the right form in order to put into Payload. That will determine how difficult of a task this is. You'd use the Payload local API for this inside of a script.



    Here is some pseudo-code for you:


    import payload from 'payload';
    
    require('dotenv').config();
    
    const { PAYLOAD_SECRET, MONGODB_URI } = process.env;
    
    const migratePosts = async () => {
      await payload.init({
        secret: PAYLOAD_SECRET,
        mongoURL: MONGODB_URI,
        local: true,
      });
    
      // Retrieve 'Posts' from keystone'
      // Modify data accordingly
      const postsToMigrate = [];
      const adjustedPostData = adjust(postsToMigrate);
    
      // Create new 'Posts' in Payload
      adjustedPostData.map(async post => {
        const newPost = await payload.create({ collection: 'posts', data: post });
      })
    
    };
    
    migratePosts();


    Also, here is a more advanced example migrating csv data which might be good to look at:

    https://github.com/payloadcms/payload/discussions/1660#discussioncomment-4485387
  • default discord avatar
    joephuz.2 years ago

    Thanks for your feedback

    @967118574445547650

    … I’ve been working on this and it’s coming along great. I actually just started running the payload and keystone in tandem on different ports. Then in the keystone just make myself a temporary endpoint to hit payloads REST api after transforming the data to to the format for payload. Mostly straightforward but the trickiest part is the media files since those are handled drastically different (better) in payload. But overall got all of my tests working, just in the grunt work phase. Finally my front end should drop in pretty painlessly just tweaking all the queries over with payloads local Api! 👍



    Another side note for the media files.. the original app is using S3 storage. I found the payload plugin which is AMAZING, but I had to trick it to port over my existing files/links. i did this by createing a basic, “not upload enabled” collection that mirrors the payload media collection schema just using text and numbers etc. because payload would error if you hit the api without a file to upload. Once I run my script to inject all the existing docs I swap the collection slugs for the temporary “not upload” collection and the real upload collection and boom! Got all the s3 files ready to go!

  • discord user avatar
    denolfe
    2 years ago

    Nice, this script might be somewhat relevant as well:

    https://github.com/payloadcms/payload/discussions/1834
  • default discord avatar
    joephuz.2 years ago

    Yes! I needed this thanks so much🙏

  • default discord avatar
    christopher.nowlan2 years ago

    I get the this error running that script



    Unable to find documents with payload


    APIError: The collection with slug media can't be found.

  • discord user avatar
    denolfe
    2 years ago

    Are you trying to regenerate the media sizes like that script is designed for? I linked to that script as an example of how to interact w/ the Payload local API via script.

  • default discord avatar
    christopher.nowlan2 years ago

    Yeah, I just trying regenerate all my images on the server



    @967118574445547650

    I resolved my issue and added a github comment here

    https://github.com/payloadcms/payload/discussions/1834#discussioncomment-4989249

    of how I resolved the issue

  • discord user avatar
    denolfe
    2 years ago
    @1009647354758054068

    Great, thanks for doing that 👍

  • default discord avatar
    christopher.nowlan2 years ago

    No worries. I am happy to assist

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.