mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-15 17:16:45 +00:00
feat: PAY-3769 add db export command (#19579)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -42,3 +42,4 @@ packages/testing/**/.cursor/rules/
|
||||
__pycache__
|
||||
packages/cli/THIRD_PARTY_LICENSES.md
|
||||
.coverage
|
||||
packages/cli/src/commands/export/outputs
|
||||
42
packages/cli/src/commands/export/__tests__/entities.test.ts
Normal file
42
packages/cli/src/commands/export/__tests__/entities.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { ExportEntitiesCommand } from '../entities';
|
||||
import { ensureDir } from 'fs-extra';
|
||||
|
||||
jest.mock('fs-extra');
|
||||
|
||||
describe('ExportEntitiesCommand', () => {
|
||||
describe('run', () => {
|
||||
it('should export entities', async () => {
|
||||
const command = new ExportEntitiesCommand();
|
||||
// @ts-expect-error Protected property
|
||||
command.flags = {
|
||||
outputDir: './exports',
|
||||
};
|
||||
// @ts-expect-error Protected property
|
||||
command.logger = {
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
await command.run();
|
||||
|
||||
expect(ensureDir).toHaveBeenCalledWith('./exports');
|
||||
// @ts-expect-error Protected property
|
||||
expect(command.logger.info).toHaveBeenCalledTimes(4);
|
||||
// @ts-expect-error Protected property
|
||||
expect(command.logger.error).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('catch', () => {
|
||||
it('should log error', () => {
|
||||
const command = new ExportEntitiesCommand();
|
||||
// @ts-expect-error Protected property
|
||||
command.logger = {
|
||||
error: jest.fn(),
|
||||
};
|
||||
command.catch(new Error('test'));
|
||||
|
||||
// @ts-expect-error Protected property
|
||||
expect(command.logger.error).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
42
packages/cli/src/commands/export/entities.ts
Normal file
42
packages/cli/src/commands/export/entities.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { Command } from '@n8n/decorators';
|
||||
import { z } from 'zod';
|
||||
import path from 'path';
|
||||
import { ensureDir } from 'fs-extra';
|
||||
|
||||
import { BaseCommand } from '../base-command';
|
||||
|
||||
const flagsSchema = z.object({
|
||||
outputDir: z
|
||||
.string()
|
||||
.describe('Output directory path')
|
||||
.default(path.join(__dirname, './outputs')),
|
||||
});
|
||||
|
||||
@Command({
|
||||
name: 'export:entities',
|
||||
description: 'Export database entities to JSON files',
|
||||
examples: ['', '--outputDir=./exports', '--outputDir=/path/to/backup'],
|
||||
flagsSchema,
|
||||
})
|
||||
export class ExportEntitiesCommand extends BaseCommand<z.infer<typeof flagsSchema>> {
|
||||
async run() {
|
||||
const outputDir = this.flags.outputDir;
|
||||
|
||||
this.logger.info('\n⚠️⚠️ This feature is currently under development. ⚠️⚠️');
|
||||
this.logger.info('\n🚀 Starting entity export...');
|
||||
this.logger.info(`📁 Output directory: ${outputDir}`);
|
||||
|
||||
await ensureDir(outputDir);
|
||||
|
||||
// TODO: Export entities
|
||||
|
||||
this.logger.info('✅ Task completed successfully! \n');
|
||||
}
|
||||
|
||||
catch(error: Error) {
|
||||
this.logger.error('❌ Error exporting entities. See log messages for details. \n');
|
||||
this.logger.error('Error details:');
|
||||
this.logger.error('\n====================================\n');
|
||||
this.logger.error(`${error.message} \n`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user