Adds new plugin-import-export initial version.
Allows for direct download and creation of downloadable collection data
stored to a json or csv uses the access control of the user creating the
request to make the file.
config options:
```ts
/**
* Collections to include the Import/Export controls in
* Defaults to all collections
*/
collections?: string[]
/**
* Enable to force the export to run synchronously
*/
disableJobsQueue?: boolean
/**
* This function takes the default export collection configured in the plugin and allows you to override it by modifying and returning it
* @param collection
* @returns collection
*/
overrideExportCollection?: (collection: CollectionOverride) => CollectionOverride
// payload.config.ts:
plugins: [
importExportPlugin({
collections: ['pages', 'users'],
overrideExportCollection: (collection) => {
collection.admin.group = 'System'
collection.upload.staticDir = path.resolve(dirname, 'uploads')
return collection
},
disableJobsQueue: true,
}),
],
```
---------
Co-authored-by: Jessica Chowdhury <jessica@trbl.design>
Co-authored-by: Kendell Joseph <kendelljoseph@gmail.com>
136 lines
2.8 KiB
TypeScript
136 lines
2.8 KiB
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import { devUser } from '../../credentials.js'
|
|
import { richTextData } from './richTextData.js'
|
|
|
|
export const seed = async (payload: Payload): Promise<boolean> => {
|
|
payload.logger.info('Seeding data...')
|
|
try {
|
|
await payload.create({
|
|
collection: 'users',
|
|
data: {
|
|
email: devUser.email,
|
|
password: devUser.password,
|
|
},
|
|
})
|
|
// create pages
|
|
for (let i = 0; i < 5; i++) {
|
|
await payload.create({
|
|
collection: 'pages',
|
|
data: {
|
|
title: `Title ${i}`,
|
|
group: {
|
|
array: [{ field1: 'test' }],
|
|
},
|
|
},
|
|
})
|
|
}
|
|
for (let i = 0; i < 5; i++) {
|
|
const doc = await payload.create({
|
|
collection: 'pages',
|
|
data: {
|
|
title: `Localized ${i}`,
|
|
localized: 'en test',
|
|
},
|
|
locale: 'en',
|
|
})
|
|
await payload.update({
|
|
collection: 'pages',
|
|
id: doc.id,
|
|
data: {
|
|
localized: 'es test',
|
|
},
|
|
locale: 'es',
|
|
})
|
|
}
|
|
for (let i = 0; i < 5; i++) {
|
|
await payload.create({
|
|
collection: 'pages',
|
|
data: {
|
|
title: `Array ${i}`,
|
|
array: [
|
|
{
|
|
field1: 'foo',
|
|
field2: 'bar',
|
|
},
|
|
{
|
|
field1: 'foo',
|
|
field2: 'baz',
|
|
},
|
|
],
|
|
},
|
|
})
|
|
}
|
|
for (let i = 0; i < 5; i++) {
|
|
await payload.create({
|
|
collection: 'pages',
|
|
data: {
|
|
title: `Array Subfield ${i}`,
|
|
array: [
|
|
{
|
|
field1: 'foo',
|
|
field2: 'bar',
|
|
},
|
|
{
|
|
field1: 'foo',
|
|
field2: 'baz',
|
|
},
|
|
],
|
|
},
|
|
})
|
|
}
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
await payload.create({
|
|
collection: 'pages',
|
|
data: {
|
|
title: `hasMany Number ${i}`,
|
|
hasManyNumber: [0, 1, 1, 2, 3, 5, 8, 13, 21],
|
|
},
|
|
})
|
|
}
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
await payload.create({
|
|
collection: 'pages',
|
|
data: {
|
|
title: `Blocks ${i}`,
|
|
blocks: [
|
|
{
|
|
blockType: 'hero',
|
|
title: 'test',
|
|
},
|
|
{
|
|
blockType: 'content',
|
|
richText: richTextData,
|
|
},
|
|
],
|
|
},
|
|
})
|
|
}
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
await payload.create({
|
|
collection: 'pages',
|
|
data: {
|
|
title: `JSON ${i}`,
|
|
},
|
|
})
|
|
}
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
await payload.create({
|
|
collection: 'pages',
|
|
data: {
|
|
title: `Jobs ${i}`,
|
|
},
|
|
})
|
|
}
|
|
|
|
return true
|
|
} catch (err) {
|
|
console.error(err)
|
|
return false
|
|
}
|
|
}
|