File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { MigrateDownArgs , MigrateUpArgs , sql } from '@payloadcms/db-postgres' ;
2+
3+ export async function up ( { db, payload } : MigrateUpArgs ) : Promise < void > {
4+ // Only target docs that have no version history — these are pre-existing docs
5+ // that were wrongly set to 'draft' by the DEFAULT 'draft' column migration.
6+ // Docs already touched through Payload after versioning was enabled have
7+ // _pages_v / _posts_v entries and should keep whatever status they have.
8+ const { rows : pageRows } = await db . execute < { id : number } > ( sql `
9+ SELECT id FROM "payload"."pages"
10+ WHERE NOT EXISTS (
11+ SELECT 1 FROM "payload"."_pages_v" WHERE "parent_id" = "pages"."id"
12+ )
13+ ` ) ;
14+
15+ for ( const { id } of pageRows ) {
16+ await payload . update ( {
17+ collection : 'pages' ,
18+ id,
19+ data : { _status : 'published' }
20+ } ) ;
21+ }
22+
23+ const { rows : postRows } = await db . execute < { id : number } > ( sql `
24+ SELECT id FROM "payload"."posts"
25+ WHERE NOT EXISTS (
26+ SELECT 1 FROM "payload"."_posts_v" WHERE "parent_id" = "posts"."id"
27+ )
28+ ` ) ;
29+
30+ for ( const { id } of postRows ) {
31+ await payload . update ( {
32+ collection : 'posts' ,
33+ id,
34+ data : { _status : 'published' }
35+ } ) ;
36+ }
37+ }
38+
39+ export async function down ( _args : MigrateDownArgs ) : Promise < void > {
40+ // No safe rollback — we cannot know which docs were previously unpublished
41+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import * as migration_20260411_000000_enum_schema_cleanup from './20260411_00000
3030import * as migration_20260412_202701_cod_295 from './20260412_202701_cod_295' ;
3131import * as migration_20260416_053006_cod_293 from './20260416_053006_cod_293' ;
3232import * as migration_20260418_101207_cod_293_drop_media_prefix from './20260418_101207_cod_293_drop_media_prefix' ;
33+ import * as migration_20260419_000000_cod_293_publish_existing from './20260419_000000_cod_293_publish_existing' ;
3334
3435export const migrations = [
3536 {
@@ -191,5 +192,10 @@ export const migrations = [
191192 up : migration_20260418_101207_cod_293_drop_media_prefix . up ,
192193 down : migration_20260418_101207_cod_293_drop_media_prefix . down ,
193194 name : '20260418_101207_cod_293_drop_media_prefix'
195+ } ,
196+ {
197+ up : migration_20260419_000000_cod_293_publish_existing . up ,
198+ down : migration_20260419_000000_cod_293_publish_existing . down ,
199+ name : '20260419_000000_cod_293_publish_existing'
194200 }
195201] ;
You can’t perform that action at this time.
0 commit comments