Skip to content

Commit bd69b30

Browse files
committed
Add data migration
1 parent 106563f commit bd69b30

File tree

5 files changed

+309
-159
lines changed

5 files changed

+309
-159
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { MigrateDownArgs, MigrateUpArgs } from "@payloadcms/db-mongodb";
2+
import { migrateSlateToLexical } from "@payloadcms/richtext-lexical/migrate";
3+
4+
export async function up({
5+
payload,
6+
req,
7+
session,
8+
}: MigrateUpArgs): Promise<void> {
9+
payload.logger.info(`Starting slate to lexical migration process...`);
10+
await migrateSlateToLexical({ payload });
11+
}
12+
13+
export async function down({
14+
payload,
15+
req,
16+
session,
17+
}: MigrateDownArgs): Promise<void> {
18+
// Migration code
19+
}

apps/roboshield/migrations/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import * as migration_20250422_064614_migration from "./20250422_064614_migration";
2+
import * as migration_20250425_082829_migration from "./20250425_082829_migration";
23

34
export const migrations = [
45
{
56
up: migration_20250422_064614_migration.up,
67
down: migration_20250422_064614_migration.down,
78
name: "20250422_064614_migration",
89
},
10+
{
11+
up: migration_20250425_082829_migration.up,
12+
down: migration_20250425_082829_migration.down,
13+
name: "20250425_082829_migration",
14+
},
915
];

apps/roboshield/payload-types.ts

Lines changed: 205 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,27 @@ export interface Page {
168168
| (
169169
| {
170170
content: {
171+
root: {
172+
type: string;
173+
children: {
174+
type: string;
175+
version: number;
176+
[k: string]: unknown;
177+
}[];
178+
direction: ("ltr" | "rtl") | null;
179+
format:
180+
| "left"
181+
| "start"
182+
| "center"
183+
| "right"
184+
| "end"
185+
| "justify"
186+
| "";
187+
indent: number;
188+
version: number;
189+
};
171190
[k: string]: unknown;
172-
}[];
191+
};
173192
id?: string | null;
174193
blockName?: string | null;
175194
blockType: "richtext";
@@ -204,8 +223,27 @@ export interface Page {
204223
name: string;
205224
value: string;
206225
description: {
226+
root: {
227+
type: string;
228+
children: {
229+
type: string;
230+
version: number;
231+
[k: string]: unknown;
232+
}[];
233+
direction: ("ltr" | "rtl") | null;
234+
format:
235+
| "left"
236+
| "start"
237+
| "center"
238+
| "right"
239+
| "end"
240+
| "justify"
241+
| "";
242+
indent: number;
243+
version: number;
244+
};
207245
[k: string]: unknown;
208-
}[];
246+
};
209247
/**
210248
* An icon to represent this statistic. SVG format is recommended.
211249
*/
@@ -222,11 +260,28 @@ export interface Page {
222260
| (
223261
| {
224262
title: string;
225-
hint?:
226-
| {
263+
hint?: {
264+
root: {
265+
type: string;
266+
children: {
267+
type: string;
268+
version: number;
227269
[k: string]: unknown;
228-
}[]
229-
| null;
270+
}[];
271+
direction: ("ltr" | "rtl") | null;
272+
format:
273+
| "left"
274+
| "start"
275+
| "center"
276+
| "right"
277+
| "end"
278+
| "justify"
279+
| "";
280+
indent: number;
281+
version: number;
282+
};
283+
[k: string]: unknown;
284+
} | null;
230285
defaultFetchExistingRobots?: boolean | null;
231286
existingRobotsTxt: string;
232287
placeholder: string;
@@ -238,11 +293,28 @@ export interface Page {
238293
}
239294
| {
240295
title: string;
241-
hint?:
242-
| {
296+
hint?: {
297+
root: {
298+
type: string;
299+
children: {
300+
type: string;
301+
version: number;
243302
[k: string]: unknown;
244-
}[]
245-
| null;
303+
}[];
304+
direction: ("ltr" | "rtl") | null;
305+
format:
306+
| "left"
307+
| "start"
308+
| "center"
309+
| "right"
310+
| "end"
311+
| "justify"
312+
| "";
313+
indent: number;
314+
version: number;
315+
};
316+
[k: string]: unknown;
317+
} | null;
246318
crawlDelay: {
247319
label: string;
248320
title: string;
@@ -261,11 +333,28 @@ export interface Page {
261333
}
262334
| {
263335
title: string;
264-
hint?:
265-
| {
336+
hint?: {
337+
root: {
338+
type: string;
339+
children: {
340+
type: string;
341+
version: number;
266342
[k: string]: unknown;
267-
}[]
268-
| null;
343+
}[];
344+
direction: ("ltr" | "rtl") | null;
345+
format:
346+
| "left"
347+
| "start"
348+
| "center"
349+
| "right"
350+
| "end"
351+
| "justify"
352+
| "";
353+
indent: number;
354+
version: number;
355+
};
356+
[k: string]: unknown;
357+
} | null;
269358
selectPlatform: {
270359
label: string;
271360
title: string;
@@ -284,11 +373,28 @@ export interface Page {
284373
}
285374
| {
286375
title: string;
287-
hint?:
288-
| {
376+
hint?: {
377+
root: {
378+
type: string;
379+
children: {
380+
type: string;
381+
version: number;
289382
[k: string]: unknown;
290-
}[]
291-
| null;
383+
}[];
384+
direction: ("ltr" | "rtl") | null;
385+
format:
386+
| "left"
387+
| "start"
388+
| "center"
389+
| "right"
390+
| "end"
391+
| "justify"
392+
| "";
393+
indent: number;
394+
version: number;
395+
};
396+
[k: string]: unknown;
397+
} | null;
292398
aiWebCrawlers: {
293399
label: string;
294400
title: string;
@@ -303,23 +409,57 @@ export interface Page {
303409
}
304410
| {
305411
title: string;
306-
hint?:
307-
| {
412+
hint?: {
413+
root: {
414+
type: string;
415+
children: {
416+
type: string;
417+
version: number;
308418
[k: string]: unknown;
309-
}[]
310-
| null;
419+
}[];
420+
direction: ("ltr" | "rtl") | null;
421+
format:
422+
| "left"
423+
| "start"
424+
| "center"
425+
| "right"
426+
| "end"
427+
| "justify"
428+
| "";
429+
indent: number;
430+
version: number;
431+
};
432+
[k: string]: unknown;
433+
} | null;
311434
placeholder: string;
312435
id?: string | null;
313436
blockName?: string | null;
314437
blockType: "site-maps";
315438
}
316439
| {
317440
title: string;
318-
hint?:
319-
| {
441+
hint?: {
442+
root: {
443+
type: string;
444+
children: {
445+
type: string;
446+
version: number;
320447
[k: string]: unknown;
321-
}[]
322-
| null;
448+
}[];
449+
direction: ("ltr" | "rtl") | null;
450+
format:
451+
| "left"
452+
| "start"
453+
| "center"
454+
| "right"
455+
| "end"
456+
| "justify"
457+
| "";
458+
indent: number;
459+
version: number;
460+
};
461+
[k: string]: unknown;
462+
} | null;
323463
placeholder: string;
324464
id?: string | null;
325465
blockName?: string | null;
@@ -379,8 +519,20 @@ export interface SiteHero {
379519
}[]
380520
| null;
381521
heroDescription: {
522+
root: {
523+
type: string;
524+
children: {
525+
type: string;
526+
version: number;
527+
[k: string]: unknown;
528+
}[];
529+
direction: ("ltr" | "rtl") | null;
530+
format: "left" | "start" | "center" | "right" | "end" | "justify" | "";
531+
indent: number;
532+
version: number;
533+
};
382534
[k: string]: unknown;
383-
}[];
535+
};
384536
heroCallToAction?: string | null;
385537
id?: string | null;
386538
blockName?: string | null;
@@ -783,8 +935,20 @@ export interface SettingsSite {
783935
id: string;
784936
title: string;
785937
description: {
938+
root: {
939+
type: string;
940+
children: {
941+
type: string;
942+
version: number;
943+
[k: string]: unknown;
944+
}[];
945+
direction: ("ltr" | "rtl") | null;
946+
format: "left" | "start" | "center" | "right" | "end" | "justify" | "";
947+
indent: number;
948+
version: number;
949+
};
786950
[k: string]: unknown;
787-
}[];
951+
};
788952
/**
789953
* Shown on main navigation bar.
790954
*/
@@ -855,8 +1019,20 @@ export interface SettingsSite {
8551019
initiative: {
8561020
title: string;
8571021
description: {
1022+
root: {
1023+
type: string;
1024+
children: {
1025+
type: string;
1026+
version: number;
1027+
[k: string]: unknown;
1028+
}[];
1029+
direction: ("ltr" | "rtl") | null;
1030+
format: "left" | "start" | "center" | "right" | "end" | "justify" | "";
1031+
indent: number;
1032+
version: number;
1033+
};
8581034
[k: string]: unknown;
859-
}[];
1035+
};
8601036
partners?:
8611037
| {
8621038
name: string;

apps/roboshield/payload.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Users from "./src/payload/collections/Users";
1111
import Site from "./src/payload/globals/Site";
1212
import { defaultLocale, locales } from "./src/payload/utils/locales";
1313
import { nodemailerAdapter } from "@payloadcms/email-nodemailer";
14+
import { SlateToLexicalFeature } from "@payloadcms/richtext-lexical/migrate";
1415

1516
const projectDir = process.cwd();
1617
loadEnvConfig(projectDir);
@@ -42,7 +43,12 @@ const smtpHost = process.env.SMTP_HOST || "smtp.sendgrid.net";
4243

4344
export default buildConfig({
4445
serverURL: appURL,
45-
editor: lexicalEditor({}),
46+
editor: lexicalEditor({
47+
features: ({ defaultFeatures }) => [
48+
...defaultFeatures,
49+
SlateToLexicalFeature({ disableHooks: true }),
50+
],
51+
}),
4652
db: mongooseAdapter({
4753
url: process.env.MONGO_URL ?? false,
4854
migrationDir: process.env.MIGRATIONS_DIR,

0 commit comments

Comments
 (0)