@nauth-toolkit/database-typeorm-postgres 0.1.25 → 0.1.26
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.
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
2
|
import type { NAuthConfig, NAuthLogger } from '@nauth-toolkit/core';
|
|
3
3
|
/**
|
|
4
4
|
* Run nauth-toolkit migrations for Postgres.
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
* This
|
|
7
|
+
* This creates a completely isolated DataSource instance for nauth migrations,
|
|
8
|
+
* ensuring zero interference with consumer migrations. The consumer's DataSource
|
|
9
|
+
* is never modified or accessed for migration purposes.
|
|
10
|
+
*
|
|
11
|
+
* @param dataSource - Consumer's DataSource (only used to extract connection config)
|
|
12
|
+
* @param logger - NAuth logger instance
|
|
13
|
+
* @param config - NAuth configuration
|
|
8
14
|
*/
|
|
9
15
|
export declare function runNAuthMigrations(dataSource: DataSource, logger: NAuthLogger, config: NAuthConfig): Promise<void>;
|
|
10
16
|
//# sourceMappingURL=run-migrations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-migrations.d.ts","sourceRoot":"","sources":["../../src/utils/run-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"run-migrations.d.ts","sourceRoot":"","sources":["../../src/utils/run-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AA+DpE;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,CA8Cf"}
|
|
@@ -1,36 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runNAuthMigrations = runNAuthMigrations;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
4
5
|
const migrations_1 = require("../migrations");
|
|
6
|
+
const entities_1 = require("../entities");
|
|
5
7
|
function getMigrationsTableName(config) {
|
|
6
8
|
const tablePrefix = config.tablePrefix ?? 'nauth_';
|
|
7
9
|
return `${tablePrefix}migrations`;
|
|
8
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Extracts connection configuration from consumer DataSource without touching it.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* This function only reads connection options and never modifies the consumer's DataSource.
|
|
16
|
+
* It supports both connection URL and individual connection parameters.
|
|
17
|
+
*
|
|
18
|
+
* @param dataSource - Consumer's DataSource instance
|
|
19
|
+
* @returns Connection configuration object
|
|
20
|
+
*/
|
|
21
|
+
function extractConnectionConfig(dataSource) {
|
|
22
|
+
const options = dataSource.options;
|
|
23
|
+
const opts = options;
|
|
24
|
+
// If connection URL is provided, use it (takes precedence)
|
|
25
|
+
if (opts.url) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'postgres',
|
|
28
|
+
url: opts.url,
|
|
29
|
+
extra: opts.extra,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Otherwise, use individual connection parameters
|
|
33
|
+
return {
|
|
34
|
+
type: 'postgres',
|
|
35
|
+
host: opts.host,
|
|
36
|
+
port: opts.port,
|
|
37
|
+
username: opts.username,
|
|
38
|
+
password: opts.password,
|
|
39
|
+
database: opts.database,
|
|
40
|
+
extra: opts.extra,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
9
43
|
/**
|
|
10
44
|
* Run nauth-toolkit migrations for Postgres.
|
|
11
45
|
*
|
|
12
46
|
* @remarks
|
|
13
|
-
* This
|
|
47
|
+
* This creates a completely isolated DataSource instance for nauth migrations,
|
|
48
|
+
* ensuring zero interference with consumer migrations. The consumer's DataSource
|
|
49
|
+
* is never modified or accessed for migration purposes.
|
|
50
|
+
*
|
|
51
|
+
* @param dataSource - Consumer's DataSource (only used to extract connection config)
|
|
52
|
+
* @param logger - NAuth logger instance
|
|
53
|
+
* @param config - NAuth configuration
|
|
14
54
|
*/
|
|
15
55
|
async function runNAuthMigrations(dataSource, logger, config) {
|
|
16
56
|
const migrationsTableName = getMigrationsTableName(config);
|
|
17
57
|
logger.log(`[nauth-toolkit] Ensuring database schema via migrations (@nauth-toolkit/database-typeorm-postgres)...`);
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
58
|
+
// Extract connection config from consumer DataSource (read-only, no modifications)
|
|
59
|
+
const connectionConfig = extractConnectionConfig(dataSource);
|
|
60
|
+
// Create a completely separate DataSource instance for nauth migrations only
|
|
61
|
+
// This ensures hard separation - consumer migrations are never touched
|
|
62
|
+
const nauthDataSource = new typeorm_1.DataSource({
|
|
63
|
+
...connectionConfig,
|
|
64
|
+
entities: [...(0, entities_1.getNAuthEntities)(), ...(0, entities_1.getNAuthTransientStorageEntities)()],
|
|
65
|
+
migrations: migrations_1.migrations,
|
|
66
|
+
migrationsTableName,
|
|
67
|
+
synchronize: false,
|
|
68
|
+
logging: false,
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
// Initialize the isolated nauth DataSource
|
|
72
|
+
await nauthDataSource.initialize();
|
|
73
|
+
logger.log(`[nauth-toolkit] Running ${migrations_1.migrations.length} NAuth migration(s) using isolated DataSource (table: ${migrationsTableName})`);
|
|
74
|
+
logger.log('[nauth-toolkit] Checking for pending migrations...');
|
|
75
|
+
// Run migrations on the isolated DataSource
|
|
76
|
+
const executed = (await nauthDataSource.runMigrations({
|
|
77
|
+
transaction: 'all',
|
|
78
|
+
}));
|
|
79
|
+
if (!executed.length) {
|
|
80
|
+
logger.log('[nauth-toolkit] No pending migrations.');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
logger.log(`[nauth-toolkit] Executed ${executed.length} migration(s):`);
|
|
84
|
+
for (const m of executed)
|
|
85
|
+
logger.log(` ${m.name}`);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
// Always destroy the isolated DataSource to clean up connections
|
|
89
|
+
if (nauthDataSource.isInitialized) {
|
|
90
|
+
await nauthDataSource.destroy();
|
|
91
|
+
}
|
|
31
92
|
}
|
|
32
|
-
logger.log(`[nauth-toolkit] Executed ${executed.length} migration(s):`);
|
|
33
|
-
for (const m of executed)
|
|
34
|
-
logger.log(` ${m.name}`);
|
|
35
93
|
}
|
|
36
94
|
//# sourceMappingURL=run-migrations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-migrations.js","sourceRoot":"","sources":["../../src/utils/run-migrations.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"run-migrations.js","sourceRoot":"","sources":["../../src/utils/run-migrations.ts"],"names":[],"mappings":";;AA4EA,gDAkDC;AA9HD,qCAAqC;AAErC,8CAA2C;AAC3C,0CAAiF;AAIjF,SAAS,sBAAsB,CAAC,MAAmB;IACjD,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,QAAQ,CAAC;IACnD,OAAO,GAAG,WAAW,YAAY,CAAC;AACpC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,uBAAuB,CAAC,UAAsB;IAUrD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IACnC,MAAM,IAAI,GAAG,OAQZ,CAAC;IAEF,2DAA2D;IAC3D,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC;IACJ,CAAC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AC,MAAM,EAAE,CAAC;YACrB,MAAM,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;YACrD,OAAO;QACT,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,4BAA4B,QAAQ,CAAC,MAAM,gBAAgB,CAAC,CAAC;QACxE,KAAK,MAAM,CAAC,IAAI,QAAQ;YAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;YAAS,CAAC;QACT,iEAAiE;QACjE,IAAI,eAAe,CAAC,aAAa,EAAE,CAAC;YAClC,MAAM,eAAe,CAAC,OAAO,EAAE,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nauth-toolkit/database-typeorm-postgres",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
4
4
|
"description": "PostgreSQL TypeORM adapter for nauth-toolkit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"format:check": "prettier --check \"src/**/*.ts\""
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@nauth-toolkit/core": "^0.1.
|
|
17
|
+
"@nauth-toolkit/core": "^0.1.26",
|
|
18
18
|
"typeorm": "^0.3.20",
|
|
19
19
|
"pg": "^8.0.0"
|
|
20
20
|
},
|