feat: PAY-3770 add db import command (#19584)

This commit is contained in:
Stephen Wright
2025-09-16 18:17:34 +01:00
committed by GitHub
parent 2435b94c2a
commit cf4a5511b6
2 changed files with 77 additions and 0 deletions

View 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();
});
});
});

View 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`);
}
}