Skip to content

Commit

Permalink
feat(cli): Add support for exporting dataset with cursor (#7068)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgulseth committed Jul 5, 2024
1 parent 0d2f0d9 commit d019845
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/@sanity/cli/test/exportImport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ describeCliTest('CLI: `sanity dataset export` / `import`', () => {
expect(filesTypes).toContain('.jpg')
})

testConcurrent('export, with mode', async () => {
const result = await runSanityCmdCommand(version, [
'dataset',
'export',
'production',
testRunArgs.exportTarball,
'--overwrite',
'--mode cursor',
])
expect(result.stdout).toMatch(/export finished/i)
expect(result.code).toBe(0)

const tarballPath = path.join(studiosPath, version, testRunArgs.exportTarball)

const stats = await stat(tarballPath)
expect(stats.isFile()).toBe(true)

// We're just checking for the existence of a few files here - the actual export
// functionality is fully tested in `@sanity/export`
const filesTypes: string[] = []
await tar.t({
file: tarballPath,
onentry: (entry) => filesTypes.push(path.extname(entry.path)),
})

expect(filesTypes).toContain('.ndjson')
expect(filesTypes).toContain('.jpg')
})

testConcurrent('import', async () => {
const result = await runSanityCmdCommand(version, [
'dataset',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Options
--types Defines which document types to export
--overwrite Overwrite any file with the same name
--asset-concurrency <num> Concurrent number of asset downloads
--mode <stream|cursor> Uses a cursor when exporting, this might be more performant for larger datasets, but might not be as accurate if the dataset is being modified during export. Defaults to stream
Examples
sanity dataset export moviedb localPath.tar.gz
Expand All @@ -36,6 +37,7 @@ interface ExportFlags {
'overwrite'?: boolean
'types'?: string
'asset-concurrency'?: string
'mode'?: string
}

interface ParsedExportFlags {
Expand All @@ -46,6 +48,7 @@ interface ParsedExportFlags {
overwrite?: boolean
types?: string[]
assetConcurrency?: number
mode?: string
}

function parseFlags(rawFlags: ExportFlags): ParsedExportFlags {
Expand Down Expand Up @@ -78,6 +81,10 @@ function parseFlags(rawFlags: ExportFlags): ParsedExportFlags {
flags.overwrite = Boolean(rawFlags.overwrite)
}

if (typeof rawFlags.mode !== 'undefined') {
flags.mode = rawFlags.mode
}

return flags
}

Expand Down

0 comments on commit d019845

Please sign in to comment.