Hi,
I've added versions: { drafts: true }
to my Articles
collection, which already contains some articles.
After doing it:
I couldn't find anything on the Internet, only one thing on the drafts documentation, but it doesn't work for me to see the "old" articles on Admin UI.
Note regarding adding versions to an existing collection
If you already have a collection with documents, and you opt in to draft functionality after you have already created existing documents, all of your old documents will not have a _status field until you resave them. For this reason, if you are adding versions into an existing collection, you might want to write your access control function to allow for users to read both documents where _status is equal to "published" as well as where _status does not exist.
Do you know how to solve it? Shall I do it via migration script or something else?
The list uses the versions collection, which makes it look like there are no documents even when the database has them. If you make a migration that saves all the documents using payload.update({ _status: 'published', where: {})
it should resave all your docs to have a version history.
thank you very much 💪
I do have same issue and i can't able to resolve it can you please guide me in details how can i resolve this ?
Help will be much appreciated !!
@rafalkowalewski can you help me on it?
@komal1220
to be honest - we are not on production still, so I just removed all data in db
but I think it could be fixed just by adding a migration script and resave all of the documents
Thanks @rafalkowalewski . Actually I do have two migration scripts and I'm bit confuse which i have to use . if you have any migration scripts can you please share with me if you don't have any problem?
Thanks!!
@DanRibbens
@komal1220
I haven't created any yet, so I can't help you with that :/
Hi @komal1220 ! I had the same problem and managed to migrate correctly.
After generating your migration file, eg:
pnpm run payload migrate:create ‘add versionning to blog post && xp post’
You modify the up()
script in /migrations/${theNameOfYourMigration}.ts
. In my case, after the await payload.db.drizzle.execute(sql...)
, I added this:
export async function up({ payload, req }: MigrateUpArgs): Promise<void> {
await payload.db.drizzle.execute(sql`...);
await payload.update({
collection: "blogPosts",
where: {},
data: { _status: "published" },
});
}
Hope this helps !
The list uses the versions collection, which makes it look like there are no documents even when the database has them. If you make a migration that saves all the documents using
payload.update({ _status: 'published', where: {})
it should resave all your docs to have a version history.
This doesn't work. The migration runs successfully but the tables/collections are not created. After removing payload.update
, the tables/collections are created
For me the provided solution worked but only when I put suggested code into a separate migration. Combined migration was timing out so I realised that the update script needs to be run in a separate transaction.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.