From cf4a5511b62c78e8854c21d8fda16a124e7b5052 Mon Sep 17 00:00:00 2001 From: Stephen Wright Date: Tue, 16 Sep 2025 18:17:34 +0100 Subject: [PATCH] feat: PAY-3770 add db import command (#19584) --- .../import/__tests__/entities.test.ts | 38 ++++++++++++++++++ packages/cli/src/commands/import/entities.ts | 39 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 packages/cli/src/commands/import/__tests__/entities.test.ts create mode 100644 packages/cli/src/commands/import/entities.ts diff --git a/packages/cli/src/commands/import/__tests__/entities.test.ts b/packages/cli/src/commands/import/__tests__/entities.test.ts new file mode 100644 index 0000000000..4e844eb982 --- /dev/null +++ b/packages/cli/src/commands/import/__tests__/entities.test.ts @@ -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(); + }); + }); +}); diff --git a/packages/cli/src/commands/import/entities.ts b/packages/cli/src/commands/import/entities.ts new file mode 100644 index 0000000000..368f1618c8 --- /dev/null +++ b/packages/cli/src/commands/import/entities.ts @@ -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> { + 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`); + } +}