I don't see my previous collections after adding in versions

default discord avatar
nh02.last year
6

I added drafts to my pageType collection, however afterwards the pages I already made in this collection didn't show anymore in the admin/collection/pageType. Below is my code I added. Does anyone know If I'm missing something?



access: {
    read: () => {
      if (isLoggedIn) {
        return true;
      }

      return {
        or: [
          {
            _status: {
              equals: 'published',
            },
          },
          {
            _status: {
              exists: false,
            },
          },
        ],
      };
    },
  },
  versions: {
    drafts: true,
  },
  • discord user avatar
    dribbens
    last year

    What happens is the list is populated from querying from _collectionname_versions, a separate collection from the main when versions are enabled. To fix it, every document that existed before versions was enabled needs to be resaved.


    There is a script in the changelog that resaves all documents in a collection. It could also be done using a PATCH request for the entire collection.



    PATCH


    /api/pageType?where[id][exists]=true


    body: {_status: 'draft'}


    headers: {


    content-type: application/json


    authorization: JWT TOKENFROMCOOKIE


    }



    Sorry for the psuedocode, I'm on mobile. I hope this gives you an idea on what to do.


    This is something we need to document better.

  • default discord avatar
    nh02.last year

    Cool! Thanks for the quick response!

  • default discord avatar
    xgzepto11 months ago

    Hey, just asking if adding _status solves your issue; I tried adding this directly to the database and the problem persists 😢

  • default discord avatar
    yageee11 months ago

    Can you share the script for resave all documents in a collection, please?



    btw, thanks for the PATCH example, works well!

  • default discord avatar
    nh02.11 months ago

    Apologies for the late response. If it's still relevavant to you, adding _status wasn't the way to go, but instead running the migrateVersions script available on payloads github repo.

  • default discord avatar
    xgzepto11 months ago

    thx for the reply 🫡 problem solved

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.