@n8n/backend-test-utils 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -46,4 +46,5 @@ exports.testModules = __importStar(require("./test-modules"));
|
|
|
46
46
|
__exportStar(require("./db/workflows"), exports);
|
|
47
47
|
__exportStar(require("./db/projects"), exports);
|
|
48
48
|
__exportStar(require("./mocking"), exports);
|
|
49
|
+
__exportStar(require("./migration-test-helpers"), exports);
|
|
49
50
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2DAA0C;AAEnC,MAAM,UAAU,GAAG,GAAW,EAAE,CACtC,IAAA,yBAAI,EAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAA,yBAAI,GAAU,CAAC,EAAE,CAAC,CAAC;AADxD,QAAA,UAAU,cAC8C;AAErE,2CAAyB;AACzB,oDAAoC;AACpC,8DAA8C;AAC9C,iDAA+B;AAC/B,gDAA8B;AAC9B,4CAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2DAA0C;AAEnC,MAAM,UAAU,GAAG,GAAW,EAAE,CACtC,IAAA,yBAAI,EAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAA,yBAAI,GAAU,CAAC,EAAE,CAAC,CAAC;AADxD,QAAA,UAAU,cAC8C;AAErE,2CAAyB;AACzB,oDAAoC;AACpC,8DAA8C;AAC9C,iDAA+B;AAC/B,gDAA8B;AAC9B,4CAA0B;AAC1B,2DAAyC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type DatabaseType } from '@n8n/db';
|
|
2
|
+
import { DataSource, type QueryRunner } from '@n8n/typeorm';
|
|
3
|
+
export interface TestMigrationContext {
|
|
4
|
+
queryRunner: QueryRunner;
|
|
5
|
+
tablePrefix: string;
|
|
6
|
+
dbType: DatabaseType;
|
|
7
|
+
isMysql: boolean;
|
|
8
|
+
isSqlite: boolean;
|
|
9
|
+
isPostgres: boolean;
|
|
10
|
+
escape: {
|
|
11
|
+
columnName(name: string): string;
|
|
12
|
+
tableName(name: string): string;
|
|
13
|
+
indexName(name: string): string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function createTestMigrationContext(dataSource: DataSource): TestMigrationContext;
|
|
17
|
+
export declare function initDbUpToMigration(beforeMigrationName: string): Promise<void>;
|
|
18
|
+
export declare function runSingleMigration(migrationName: string): Promise<void>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTestMigrationContext = createTestMigrationContext;
|
|
4
|
+
exports.initDbUpToMigration = initDbUpToMigration;
|
|
5
|
+
exports.runSingleMigration = runSingleMigration;
|
|
6
|
+
const config_1 = require("@n8n/config");
|
|
7
|
+
const db_1 = require("@n8n/db");
|
|
8
|
+
const di_1 = require("@n8n/di");
|
|
9
|
+
const typeorm_1 = require("@n8n/typeorm");
|
|
10
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
11
|
+
async function reinitializeDataConnection() {
|
|
12
|
+
const dbConnection = di_1.Container.get(db_1.DbConnection);
|
|
13
|
+
await dbConnection.close();
|
|
14
|
+
await dbConnection.init();
|
|
15
|
+
}
|
|
16
|
+
function createTestMigrationContext(dataSource) {
|
|
17
|
+
const globalConfig = di_1.Container.get(config_1.GlobalConfig);
|
|
18
|
+
const dbType = globalConfig.database.type;
|
|
19
|
+
const tablePrefix = globalConfig.database.tablePrefix;
|
|
20
|
+
const queryRunner = dataSource.createQueryRunner();
|
|
21
|
+
return {
|
|
22
|
+
queryRunner,
|
|
23
|
+
tablePrefix,
|
|
24
|
+
dbType,
|
|
25
|
+
isMysql: ['mariadb', 'mysqldb'].includes(dbType),
|
|
26
|
+
isSqlite: dbType === 'sqlite',
|
|
27
|
+
isPostgres: dbType === 'postgresdb',
|
|
28
|
+
escape: {
|
|
29
|
+
columnName: (name) => queryRunner.connection.driver.escape(name),
|
|
30
|
+
tableName: (name) => queryRunner.connection.driver.escape(`${tablePrefix}${name}`),
|
|
31
|
+
indexName: (name) => queryRunner.connection.driver.escape(`IDX_${tablePrefix}${name}`),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function initDbUpToMigration(beforeMigrationName) {
|
|
36
|
+
const dataSource = di_1.Container.get(typeorm_1.DataSource);
|
|
37
|
+
if (!Array.isArray(dataSource.options.migrations)) {
|
|
38
|
+
throw new n8n_workflow_1.UnexpectedError('Database migrations are not an array');
|
|
39
|
+
}
|
|
40
|
+
const allMigrations = dataSource.options.migrations;
|
|
41
|
+
const targetIndex = allMigrations.findIndex((m) => m.name === beforeMigrationName);
|
|
42
|
+
if (targetIndex === -1) {
|
|
43
|
+
throw new n8n_workflow_1.UnexpectedError(`Migration "${beforeMigrationName}" not found`);
|
|
44
|
+
}
|
|
45
|
+
const migrationsToRun = allMigrations.slice(0, targetIndex);
|
|
46
|
+
dataSource.options.migrations = migrationsToRun;
|
|
47
|
+
try {
|
|
48
|
+
await reinitializeDataConnection();
|
|
49
|
+
await di_1.Container.get(db_1.DbConnection).migrate();
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
dataSource.options.migrations = allMigrations;
|
|
53
|
+
await reinitializeDataConnection();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function runSingleMigration(migrationName) {
|
|
57
|
+
const dataSource = di_1.Container.get(typeorm_1.DataSource);
|
|
58
|
+
const allMigrations = dataSource.options.migrations;
|
|
59
|
+
const migration = allMigrations.find((m) => m.name === migrationName);
|
|
60
|
+
if (!migration) {
|
|
61
|
+
throw new n8n_workflow_1.UnexpectedError(`Migration "${migrationName}" not found`);
|
|
62
|
+
}
|
|
63
|
+
dataSource.options.migrations = [migration];
|
|
64
|
+
try {
|
|
65
|
+
await reinitializeDataConnection();
|
|
66
|
+
await di_1.Container.get(db_1.DbConnection).migrate();
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
dataSource.options.migrations = allMigrations;
|
|
70
|
+
await reinitializeDataConnection();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=migration-test-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-test-helpers.js","sourceRoot":"","sources":["../src/migration-test-helpers.ts"],"names":[],"mappings":";;AAiCA,gEAmBC;AASD,kDA6BC;AASD,gDAwBC;AA3HD,wCAA2C;AAC3C,gCAA0E;AAC1E,gCAAoC;AACpC,0CAA4D;AAC5D,+CAA+C;AAE/C,KAAK,UAAU,0BAA0B;IACxC,MAAM,YAAY,GAAG,cAAS,CAAC,GAAG,CAAC,iBAAY,CAAC,CAAC;IACjD,MAAM,YAAY,CAAC,KAAK,EAAE,CAAC;IAC3B,MAAM,YAAY,CAAC,IAAI,EAAE,CAAC;AAC3B,CAAC;AAuBD,SAAgB,0BAA0B,CAAC,UAAsB;IAChE,MAAM,YAAY,GAAG,cAAS,CAAC,GAAG,CAAC,qBAAY,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC1C,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC;IACtD,MAAM,WAAW,GAAG,UAAU,CAAC,iBAAiB,EAAE,CAAC;IAEnD,OAAO;QACN,WAAW;QACX,WAAW;QACX,MAAM;QACN,OAAO,EAAE,CAAC,SAAS,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|
|
7
7
|
"files": [
|
|
8
8
|
"dist/**/*",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"LICENSE.md",
|
|
10
|
+
"LICENSE_EE.md"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@n8n/typeorm": "0.3.20-
|
|
13
|
+
"@n8n/typeorm": "0.3.20-13",
|
|
14
14
|
"jest-mock-extended": "^3.0.4",
|
|
15
15
|
"reflect-metadata": "0.2.2",
|
|
16
16
|
"uuid": "10.0.0",
|
|
17
|
-
"@n8n/
|
|
17
|
+
"@n8n/backend-common": "^0.26.0",
|
|
18
|
+
"@n8n/config": "^1.58.0",
|
|
18
19
|
"@n8n/constants": "^0.13.0",
|
|
19
|
-
"@n8n/
|
|
20
|
-
"@n8n/
|
|
21
|
-
"@n8n/permissions": "^0.
|
|
22
|
-
"n8n-workflow": "^1.
|
|
23
|
-
"@n8n/di": "^0.9.0"
|
|
20
|
+
"@n8n/db": "^0.27.0",
|
|
21
|
+
"@n8n/di": "^0.9.0",
|
|
22
|
+
"@n8n/permissions": "^0.39.0",
|
|
23
|
+
"n8n-workflow": "^1.113.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@n8n/typescript-config": "1.3.0"
|