mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
feat: PAY-3770 add db import command (#19584)
This commit is contained in:
38
packages/cli/src/commands/import/__tests__/entities.test.ts
Normal file
38
packages/cli/src/commands/import/__tests__/entities.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { ImportEntitiesCommand } from '../entities';
|
||||
|
||||
describe('ImportEntitiesCommand', () => {
|
||||
describe('run', () => {
|
||||
it('should import entities', async () => {
|
||||
const command = new ImportEntitiesCommand();
|
||||
// @ts-expect-error Protected property
|
||||
command.flags = {
|
||||
inputDir: './exports',
|
||||
};
|
||||
// @ts-expect-error Protected property
|
||||
command.logger = {
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
await command.run();
|
||||
|
||||
// @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 ImportEntitiesCommand();
|
||||
// @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();
|
||||
});
|
||||
});
|
||||
});
|
||||
39
packages/cli/src/commands/import/entities.ts
Normal file
39
packages/cli/src/commands/import/entities.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Command } from '@n8n/decorators';
|
||||
import { z } from 'zod';
|
||||
import path from 'path';
|
||||
|
||||
import { BaseCommand } from '../base-command';
|
||||
|
||||
const flagsSchema = z.object({
|
||||
inputDir: z
|
||||
.string()
|
||||
.describe('Input directory that holds output files for import')
|
||||
.default(path.join(__dirname, './outputs')),
|
||||
});
|
||||
|
||||
@Command({
|
||||
name: 'import:entities',
|
||||
description: 'Import database entities from JSON files',
|
||||
examples: ['', '--inputDir=./exports', '--inputDir=/path/to/backup'],
|
||||
flagsSchema,
|
||||
})
|
||||
export class ImportEntitiesCommand extends BaseCommand<z.infer<typeof flagsSchema>> {
|
||||
async run() {
|
||||
const inputDir = this.flags.inputDir;
|
||||
|
||||
this.logger.info('\n⚠️⚠️ This feature is currently under development. ⚠️⚠️');
|
||||
this.logger.info('\n🚀 Starting entity import...');
|
||||
this.logger.info(`📁 Input directory: ${inputDir}`);
|
||||
|
||||
// TODO: Import entities
|
||||
|
||||
this.logger.info('✅ Task completed successfully! \n');
|
||||
}
|
||||
|
||||
catch(error: Error) {
|
||||
this.logger.error('❌ Error importing 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