Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Add support for exporting dataset with cursor #7068

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading