@javalabs/prisma-client 1.0.25 → 1.0.27
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/package.json +5 -5
- package/prisma/schema.prisma +0 -4
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -34
- package/dist/index.js.map +0 -1
- package/dist/prisma-factory.service.d.ts +0 -9
- package/dist/prisma-factory.service.js +0 -47
- package/dist/prisma-factory.service.js.map +0 -1
- package/dist/prisma.module.d.ts +0 -2
- package/dist/prisma.module.js +0 -23
- package/dist/prisma.module.js.map +0 -1
- package/dist/prisma.service.d.ts +0 -6
- package/dist/prisma.service.js +0 -27
- package/dist/prisma.service.js.map +0 -1
- package/dist/scripts/add-uuid-to-table.d.ts +0 -8
- package/dist/scripts/add-uuid-to-table.js +0 -98
- package/dist/scripts/add-uuid-to-table.js.map +0 -1
- package/dist/scripts/create-tenant-schemas.d.ts +0 -1
- package/dist/scripts/create-tenant-schemas.js +0 -117
- package/dist/scripts/create-tenant-schemas.js.map +0 -1
- package/dist/scripts/data-migration/batch-migrator.d.ts +0 -20
- package/dist/scripts/data-migration/batch-migrator.js +0 -134
- package/dist/scripts/data-migration/batch-migrator.js.map +0 -1
- package/dist/scripts/data-migration/data-transformer.d.ts +0 -26
- package/dist/scripts/data-migration/data-transformer.js +0 -278
- package/dist/scripts/data-migration/data-transformer.js.map +0 -1
- package/dist/scripts/data-migration/db-connector.d.ts +0 -12
- package/dist/scripts/data-migration/db-connector.js +0 -94
- package/dist/scripts/data-migration/db-connector.js.map +0 -1
- package/dist/scripts/data-migration/dependency-resolver.d.ts +0 -18
- package/dist/scripts/data-migration/dependency-resolver.js +0 -132
- package/dist/scripts/data-migration/dependency-resolver.js.map +0 -1
- package/dist/scripts/data-migration/entity-discovery.d.ts +0 -11
- package/dist/scripts/data-migration/entity-discovery.js +0 -152
- package/dist/scripts/data-migration/entity-discovery.js.map +0 -1
- package/dist/scripts/data-migration/foreign-key-manager.d.ts +0 -18
- package/dist/scripts/data-migration/foreign-key-manager.js +0 -160
- package/dist/scripts/data-migration/foreign-key-manager.js.map +0 -1
- package/dist/scripts/data-migration/migration-tool.d.ts +0 -48
- package/dist/scripts/data-migration/migration-tool.js +0 -290
- package/dist/scripts/data-migration/migration-tool.js.map +0 -1
- package/dist/scripts/data-migration/schema-utils.d.ts +0 -18
- package/dist/scripts/data-migration/schema-utils.js +0 -207
- package/dist/scripts/data-migration/schema-utils.js.map +0 -1
- package/dist/scripts/data-migration/tenant-migrator.d.ts +0 -15
- package/dist/scripts/data-migration/tenant-migrator.js +0 -117
- package/dist/scripts/data-migration/tenant-migrator.js.map +0 -1
- package/dist/scripts/data-migration/typecast-manager.d.ts +0 -9
- package/dist/scripts/data-migration/typecast-manager.js +0 -179
- package/dist/scripts/data-migration/typecast-manager.js.map +0 -1
- package/dist/scripts/data-migration/types.d.ts +0 -100
- package/dist/scripts/data-migration/types.js +0 -3
- package/dist/scripts/data-migration/types.js.map +0 -1
- package/dist/scripts/database-initializer.d.ts +0 -5
- package/dist/scripts/database-initializer.js +0 -45
- package/dist/scripts/database-initializer.js.map +0 -1
- package/dist/scripts/drop-database.d.ts +0 -10
- package/dist/scripts/drop-database.js +0 -81
- package/dist/scripts/drop-database.js.map +0 -1
- package/dist/scripts/encrypt-user-passwords.d.ts +0 -1
- package/dist/scripts/encrypt-user-passwords.js +0 -33
- package/dist/scripts/encrypt-user-passwords.js.map +0 -1
- package/dist/scripts/error-handler.d.ts +0 -12
- package/dist/scripts/error-handler.js +0 -82
- package/dist/scripts/error-handler.js.map +0 -1
- package/dist/scripts/fix-data-types.d.ts +0 -10
- package/dist/scripts/fix-data-types.js +0 -185
- package/dist/scripts/fix-data-types.js.map +0 -1
- package/dist/scripts/fix-enum-values.d.ts +0 -17
- package/dist/scripts/fix-enum-values.js +0 -234
- package/dist/scripts/fix-enum-values.js.map +0 -1
- package/dist/scripts/fix-schema-discrepancies.d.ts +0 -21
- package/dist/scripts/fix-schema-discrepancies.js +0 -240
- package/dist/scripts/fix-schema-discrepancies.js.map +0 -1
- package/dist/scripts/fix-table-indexes.d.ts +0 -26
- package/dist/scripts/fix-table-indexes.js +0 -460
- package/dist/scripts/fix-table-indexes.js.map +0 -1
- package/dist/scripts/migrate-schema-structure.d.ts +0 -1
- package/dist/scripts/migrate-schema-structure.js +0 -76
- package/dist/scripts/migrate-schema-structure.js.map +0 -1
- package/dist/scripts/migrate-uuid.d.ts +0 -2
- package/dist/scripts/migrate-uuid.js +0 -57
- package/dist/scripts/migrate-uuid.js.map +0 -1
- package/dist/scripts/post-migration-validator.d.ts +0 -34
- package/dist/scripts/post-migration-validator.js +0 -363
- package/dist/scripts/post-migration-validator.js.map +0 -1
- package/dist/scripts/pre-migration-validator.d.ts +0 -25
- package/dist/scripts/pre-migration-validator.js +0 -491
- package/dist/scripts/pre-migration-validator.js.map +0 -1
- package/dist/scripts/reset-database.d.ts +0 -17
- package/dist/scripts/reset-database.js +0 -202
- package/dist/scripts/reset-database.js.map +0 -1
- package/dist/scripts/retry-failed-migrations.d.ts +0 -14
- package/dist/scripts/retry-failed-migrations.js +0 -301
- package/dist/scripts/retry-failed-migrations.js.map +0 -1
- package/dist/scripts/run-migration.d.ts +0 -1
- package/dist/scripts/run-migration.js +0 -512
- package/dist/scripts/run-migration.js.map +0 -1
- package/dist/scripts/schema-sync.d.ts +0 -1
- package/dist/scripts/schema-sync.js +0 -85
- package/dist/scripts/schema-sync.js.map +0 -1
- package/dist/scripts/sequence-sync-cli.d.ts +0 -2
- package/dist/scripts/sequence-sync-cli.js +0 -287
- package/dist/scripts/sequence-sync-cli.js.map +0 -1
- package/dist/scripts/sequence-synchronizer.d.ts +0 -8
- package/dist/scripts/sequence-synchronizer.js +0 -88
- package/dist/scripts/sequence-synchronizer.js.map +0 -1
- package/dist/scripts/sync-enum-types.d.ts +0 -13
- package/dist/scripts/sync-enum-types.js +0 -139
- package/dist/scripts/sync-enum-types.js.map +0 -1
- package/dist/scripts/sync-enum-values.d.ts +0 -20
- package/dist/scripts/sync-enum-values.js +0 -336
- package/dist/scripts/sync-enum-values.js.map +0 -1
- package/dist/scripts/truncate-database.d.ts +0 -10
- package/dist/scripts/truncate-database.js +0 -100
- package/dist/scripts/truncate-database.js.map +0 -1
- package/dist/scripts/verify-migration-setup.d.ts +0 -11
- package/dist/scripts/verify-migration-setup.js +0 -120
- package/dist/scripts/verify-migration-setup.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/prisma/migrations/add_athena_match_fields.sql +0 -13
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@javalabs/prisma-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "Shared Prisma client for Tupay microservices",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"private": false,
|
|
8
8
|
"publishConfig": {
|
|
9
|
-
"access": "
|
|
9
|
+
"access": "restricted"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsc",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"migrate:data": "node dist/scripts/run-migration.js migrate",
|
|
17
17
|
"migrate:data:force": "node dist/scripts/run-migration.js migrate --force",
|
|
18
18
|
"migrate:data:yes": "node dist/scripts/run-migration.js migrate -y",
|
|
19
|
-
"postinstall": "npx prisma
|
|
19
|
+
"postinstall": "npx prisma generate"
|
|
20
20
|
},
|
|
21
21
|
"prisma": {
|
|
22
22
|
"schema": "prisma/schema.prisma"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@nestjs/common": "^10.0.0",
|
|
29
29
|
"@nestjs/core": "^10.0.0",
|
|
30
|
-
"@prisma/client": "6.17.1",
|
|
30
|
+
"@prisma/client": "^6.17.1",
|
|
31
31
|
"bcrypt": "^6.0.0",
|
|
32
32
|
"commander": "^11.1.0",
|
|
33
33
|
"dotenv": "^16.4.7",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/bcrypt": "^5.0.2",
|
|
39
39
|
"@types/node": "^20.3.1",
|
|
40
40
|
"@types/pg": "^8.11.11",
|
|
41
|
-
"prisma": "6.17.1",
|
|
41
|
+
"prisma": "^6.17.1",
|
|
42
42
|
"typescript": "^5.2.2"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/prisma/schema.prisma
CHANGED
|
@@ -253,9 +253,6 @@ model manual_payments {
|
|
|
253
253
|
country_code String? @db.VarChar(10)
|
|
254
254
|
bank_account_id Int?
|
|
255
255
|
transaction_id Int?
|
|
256
|
-
athena_matched Boolean @default(false)
|
|
257
|
-
athena_match_id String? @db.VarChar(255)
|
|
258
|
-
athena_matched_at DateTime? @db.Timestamptz(6)
|
|
259
256
|
transaction transactions? @relation(fields: [transaction_id], references: [id])
|
|
260
257
|
manual_transfer_bank_acounts manual_transfer_bank_acounts? @relation(fields: [bank_account_id], references: [id])
|
|
261
258
|
users_manual_payments_processed_byTousers users? @relation("manual_payments_processed_byTousers", fields: [processed_by], references: [user_id])
|
|
@@ -401,7 +398,6 @@ model transactions {
|
|
|
401
398
|
fixed_fee Decimal? @default(0) @db.Decimal(10, 2)
|
|
402
399
|
total_commission_fee Decimal? @default(0) @db.Decimal(10, 2)
|
|
403
400
|
total_operation Decimal? @default(0) @db.Decimal(10, 2)
|
|
404
|
-
amount_received Decimal? @db.Decimal(10, 2)
|
|
405
401
|
toku toku?
|
|
406
402
|
account_type enum_account_type?
|
|
407
403
|
daily_logs daily_logs[]
|
package/dist/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { PrismaClient } from "@prisma/client";
|
|
2
|
-
import { PrismaModule } from "./prisma.module";
|
|
3
|
-
import { PrismaService } from "./prisma.service";
|
|
4
|
-
import { PrismaFactoryService } from "./prisma-factory.service";
|
|
5
|
-
export declare const prisma: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, import(".prisma/client").Prisma.LogLevel, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
6
|
-
export { PrismaModule, PrismaService, PrismaFactoryService };
|
|
7
|
-
export * from "@prisma/client";
|
package/dist/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var _a;
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.PrismaFactoryService = exports.PrismaService = exports.PrismaModule = exports.prisma = void 0;
|
|
19
|
-
const client_1 = require("@prisma/client");
|
|
20
|
-
const prisma_module_1 = require("./prisma.module");
|
|
21
|
-
Object.defineProperty(exports, "PrismaModule", { enumerable: true, get: function () { return prisma_module_1.PrismaModule; } });
|
|
22
|
-
const prisma_service_1 = require("./prisma.service");
|
|
23
|
-
Object.defineProperty(exports, "PrismaService", { enumerable: true, get: function () { return prisma_service_1.PrismaService; } });
|
|
24
|
-
const prisma_factory_service_1 = require("./prisma-factory.service");
|
|
25
|
-
Object.defineProperty(exports, "PrismaFactoryService", { enumerable: true, get: function () { return prisma_factory_service_1.PrismaFactoryService; } });
|
|
26
|
-
const prismaClientSingleton = () => {
|
|
27
|
-
return new client_1.PrismaClient();
|
|
28
|
-
};
|
|
29
|
-
const globalForPrisma = globalThis;
|
|
30
|
-
exports.prisma = (_a = globalForPrisma.prisma) !== null && _a !== void 0 ? _a : prismaClientSingleton();
|
|
31
|
-
if (process.env.NODE_ENV !== "production")
|
|
32
|
-
globalForPrisma.prisma = exports.prisma;
|
|
33
|
-
__exportStar(require("@prisma/client"), exports);
|
|
34
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAA8C;AAC9C,mDAA+C;AAoBtC,6FApBA,4BAAY,OAoBA;AAnBrB,qDAAiD;AAmB1B,8FAnBd,8BAAa,OAmBc;AAlBpC,qEAAgE;AAkB1B,qGAlB7B,6CAAoB,OAkB6B;AAf1D,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACjC,OAAO,IAAI,qBAAY,EAAE,CAAC;AAC5B,CAAC,CAAC;AAIF,MAAM,eAAe,GAAG,UAEvB,CAAC;AAEW,QAAA,MAAM,GAAG,MAAA,eAAe,CAAC,MAAM,mCAAI,qBAAqB,EAAE,CAAC;AAExE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAAE,eAAe,CAAC,MAAM,GAAG,cAAM,CAAC;AAI3E,iDAA+B"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { OnModuleDestroy } from '@nestjs/common';
|
|
2
|
-
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
export declare class PrismaFactoryService implements OnModuleDestroy {
|
|
4
|
-
private clients;
|
|
5
|
-
private readonly logger;
|
|
6
|
-
getClient(tenantId: string): PrismaClient;
|
|
7
|
-
getMasterClient(): PrismaClient;
|
|
8
|
-
onModuleDestroy(): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var PrismaFactoryService_1;
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.PrismaFactoryService = void 0;
|
|
11
|
-
const common_1 = require("@nestjs/common");
|
|
12
|
-
const client_1 = require("@prisma/client");
|
|
13
|
-
let PrismaFactoryService = PrismaFactoryService_1 = class PrismaFactoryService {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.clients = new Map();
|
|
16
|
-
this.logger = new common_1.Logger(PrismaFactoryService_1.name);
|
|
17
|
-
}
|
|
18
|
-
getClient(tenantId) {
|
|
19
|
-
if (!this.clients.has(tenantId)) {
|
|
20
|
-
this.logger.log(`Creating new Prisma client for tenant: ${tenantId}`);
|
|
21
|
-
const client = new client_1.PrismaClient({
|
|
22
|
-
datasources: {
|
|
23
|
-
db: {
|
|
24
|
-
url: `${process.env.DATABASE_URL}?schema=${tenantId}`,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
this.clients.set(tenantId, client);
|
|
29
|
-
}
|
|
30
|
-
return this.clients.get(tenantId);
|
|
31
|
-
}
|
|
32
|
-
getMasterClient() {
|
|
33
|
-
return this.getClient('public');
|
|
34
|
-
}
|
|
35
|
-
async onModuleDestroy() {
|
|
36
|
-
this.logger.log('Disconnecting all Prisma clients');
|
|
37
|
-
for (const [tenantId, client] of this.clients.entries()) {
|
|
38
|
-
this.logger.log(`Disconnecting client for tenant: ${tenantId}`);
|
|
39
|
-
await client.$disconnect();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
exports.PrismaFactoryService = PrismaFactoryService;
|
|
44
|
-
exports.PrismaFactoryService = PrismaFactoryService = PrismaFactoryService_1 = __decorate([
|
|
45
|
-
(0, common_1.Injectable)()
|
|
46
|
-
], PrismaFactoryService);
|
|
47
|
-
//# sourceMappingURL=prisma-factory.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prisma-factory.service.js","sourceRoot":"","sources":["../src/prisma-factory.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAqE;AACrE,2CAA8C;AAGvC,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAA1B;QACG,YAAO,GAA8B,IAAI,GAAG,EAAE,CAAC;QACtC,WAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAC;IAkClE,CAAC;IAhCC,SAAS,CAAC,QAAgB;QACxB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,0CAA0C,QAAQ,EAAE,CAAC,CAAC;YAGtE,MAAM,MAAM,GAAG,IAAI,qBAAY,CAAC;gBAC9B,WAAW,EAAE;oBACX,EAAE,EAAE;wBACF,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,WAAW,QAAQ,EAAE;qBACtD;iBACF;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAGD,eAAe;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;QAEpD,KAAK,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YACxD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,oCAAoC,QAAQ,EAAE,CAAC,CAAC;YAChE,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;CACF,CAAA;AApCY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CAoChC"}
|
package/dist/prisma.module.d.ts
DELETED
package/dist/prisma.module.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.PrismaModule = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const prisma_service_1 = require("./prisma.service");
|
|
12
|
-
const prisma_factory_service_1 = require("./prisma-factory.service");
|
|
13
|
-
let PrismaModule = class PrismaModule {
|
|
14
|
-
};
|
|
15
|
-
exports.PrismaModule = PrismaModule;
|
|
16
|
-
exports.PrismaModule = PrismaModule = __decorate([
|
|
17
|
-
(0, common_1.Global)(),
|
|
18
|
-
(0, common_1.Module)({
|
|
19
|
-
providers: [prisma_service_1.PrismaService, prisma_factory_service_1.PrismaFactoryService],
|
|
20
|
-
exports: [prisma_service_1.PrismaService, prisma_factory_service_1.PrismaFactoryService],
|
|
21
|
-
})
|
|
22
|
-
], PrismaModule);
|
|
23
|
-
//# sourceMappingURL=prisma.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["../src/prisma.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,qDAAiD;AACjD,qEAAgE;AAOzD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IALxB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,8BAAa,EAAE,6CAAoB,CAAC;QAChD,OAAO,EAAE,CAAC,8BAAa,EAAE,6CAAoB,CAAC;KAC/C,CAAC;GACW,YAAY,CAAG"}
|
package/dist/prisma.service.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
|
2
|
-
export declare class PrismaService implements OnModuleInit, OnModuleDestroy {
|
|
3
|
-
onModuleInit(): Promise<void>;
|
|
4
|
-
onModuleDestroy(): Promise<void>;
|
|
5
|
-
get client(): import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, import(".prisma/client").Prisma.LogLevel, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
6
|
-
}
|
package/dist/prisma.service.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.PrismaService = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const index_1 = require("./index");
|
|
12
|
-
let PrismaService = class PrismaService {
|
|
13
|
-
async onModuleInit() {
|
|
14
|
-
await index_1.prisma.$connect();
|
|
15
|
-
}
|
|
16
|
-
async onModuleDestroy() {
|
|
17
|
-
await index_1.prisma.$disconnect();
|
|
18
|
-
}
|
|
19
|
-
get client() {
|
|
20
|
-
return index_1.prisma;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
exports.PrismaService = PrismaService;
|
|
24
|
-
exports.PrismaService = PrismaService = __decorate([
|
|
25
|
-
(0, common_1.Injectable)()
|
|
26
|
-
], PrismaService);
|
|
27
|
-
//# sourceMappingURL=prisma.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.service.js","sourceRoot":"","sources":["../src/prisma.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2E;AAC3E,mCAAiC;AAG1B,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,KAAK,CAAC,YAAY;QAChB,MAAM,cAAM,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,cAAM,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,cAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAZY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CAYzB"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
interface AddUuidOptions {
|
|
2
|
-
tableName: string;
|
|
3
|
-
columnName?: string;
|
|
4
|
-
makeRequired?: boolean;
|
|
5
|
-
addDefault?: boolean;
|
|
6
|
-
}
|
|
7
|
-
declare function addUuidToTable({ tableName, columnName, makeRequired, addDefault, }: AddUuidOptions): Promise<void>;
|
|
8
|
-
export { addUuidToTable };
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addUuidToTable = addUuidToTable;
|
|
4
|
-
const client_1 = require("@prisma/client");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
|
-
const util_1 = require("util");
|
|
7
|
-
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
8
|
-
const prisma = new client_1.PrismaClient();
|
|
9
|
-
async function addUuidToTable({ tableName, columnName = "uuid", makeRequired = false, addDefault = false, }) {
|
|
10
|
-
try {
|
|
11
|
-
console.log(`🚀 Iniciando proceso de añadir UUID a la tabla ${tableName}...`);
|
|
12
|
-
const tableExists = await prisma.$queryRaw `
|
|
13
|
-
SELECT EXISTS (
|
|
14
|
-
SELECT FROM information_schema.tables
|
|
15
|
-
WHERE table_name = ${tableName}
|
|
16
|
-
);
|
|
17
|
-
`;
|
|
18
|
-
if (!tableExists[0].exists) {
|
|
19
|
-
throw new Error(`La tabla ${tableName} no existe`);
|
|
20
|
-
}
|
|
21
|
-
const columnExists = await prisma.$queryRaw `
|
|
22
|
-
SELECT EXISTS (
|
|
23
|
-
SELECT FROM information_schema.columns
|
|
24
|
-
WHERE table_name = ${tableName}
|
|
25
|
-
AND column_name = ${columnName}
|
|
26
|
-
);
|
|
27
|
-
`;
|
|
28
|
-
if (columnExists[0].exists) {
|
|
29
|
-
console.log(`⚠️ La columna ${columnName} ya existe en la tabla ${tableName}`);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
console.log("📦 Habilitando extensión uuid-ossp...");
|
|
33
|
-
await prisma.$executeRaw `CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`;
|
|
34
|
-
console.log(`📝 Añadiendo columna ${columnName}...`);
|
|
35
|
-
await prisma.$executeRaw `
|
|
36
|
-
ALTER TABLE ${tableName}
|
|
37
|
-
ADD COLUMN ${columnName} VARCHAR(255);
|
|
38
|
-
`;
|
|
39
|
-
console.log("🔄 Actualizando registros existentes con UUIDs...");
|
|
40
|
-
await prisma.$executeRaw `
|
|
41
|
-
UPDATE ${tableName}
|
|
42
|
-
SET ${columnName} = uuid_generate_v4()
|
|
43
|
-
WHERE ${columnName} IS NULL;
|
|
44
|
-
`;
|
|
45
|
-
console.log("📊 Creando índice...");
|
|
46
|
-
await prisma.$executeRaw `
|
|
47
|
-
CREATE INDEX idx_${tableName}_${columnName}
|
|
48
|
-
ON ${tableName}(${columnName});
|
|
49
|
-
`;
|
|
50
|
-
console.log("🔒 Añadiendo restricción unique...");
|
|
51
|
-
await prisma.$executeRaw `
|
|
52
|
-
ALTER TABLE ${tableName}
|
|
53
|
-
ADD CONSTRAINT ${tableName}_${columnName}_key
|
|
54
|
-
UNIQUE (${columnName});
|
|
55
|
-
`;
|
|
56
|
-
if (makeRequired) {
|
|
57
|
-
console.log("⚠️ Haciendo la columna NOT NULL...");
|
|
58
|
-
await prisma.$executeRaw `
|
|
59
|
-
ALTER TABLE ${tableName}
|
|
60
|
-
ALTER COLUMN ${columnName} SET NOT NULL;
|
|
61
|
-
`;
|
|
62
|
-
}
|
|
63
|
-
if (addDefault) {
|
|
64
|
-
console.log("⚡ Añadiendo valor por defecto...");
|
|
65
|
-
await prisma.$executeRaw `
|
|
66
|
-
ALTER TABLE ${tableName}
|
|
67
|
-
ALTER COLUMN ${columnName}
|
|
68
|
-
SET DEFAULT uuid_generate_v4();
|
|
69
|
-
`;
|
|
70
|
-
}
|
|
71
|
-
console.log(`✅ Proceso completado exitosamente para la tabla ${tableName}`);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
console.error("❌ Error durante el proceso:", error);
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
finally {
|
|
78
|
-
await prisma.$disconnect();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async function main() {
|
|
82
|
-
try {
|
|
83
|
-
await addUuidToTable({
|
|
84
|
-
tableName: "transactions",
|
|
85
|
-
columnName: "uuid",
|
|
86
|
-
makeRequired: false,
|
|
87
|
-
addDefault: false,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
console.error("Error en el proceso principal:", error);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (require.main === module) {
|
|
96
|
-
main();
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=add-uuid-to-table.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add-uuid-to-table.js","sourceRoot":"","sources":["../../src/scripts/add-uuid-to-table.ts"],"names":[],"mappings":";;AAyIS,wCAAc;AAzIvB,2CAA8C;AAC9C,iDAAqC;AACrC,+BAAiC;AAEjC,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;AAClC,MAAM,MAAM,GAAG,IAAI,qBAAY,EAAE,CAAC;AASlC,KAAK,UAAU,cAAc,CAAC,EAC5B,SAAS,EACT,UAAU,GAAG,MAAM,EACnB,YAAY,GAAG,KAAK,EACpB,UAAU,GAAG,KAAK,GACH;IACf,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CACT,kDAAkD,SAAS,KAAK,CACjE,CAAC;QAGF,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,SAAS,CAAA;;;6BAGjB,SAAS;;KAEjC,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,YAAY,SAAS,YAAY,CAAC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AS;uBACR,UAAU;;OAE1B,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,GAAG,CACT,mDAAmD,SAAS,EAAE,CAC/D,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACpD,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC;AAGD,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,MAAM,cAAc,CAAC;YACnB,SAAS,EAAE,cAAc;YACzB,UAAU,EAAE,MAAM;YAClB,YAAY,EAAE,KAAK;YACnB,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAGD,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,CAAC;AACT,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const client_1 = require("@prisma/client");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const dotenv = require("dotenv");
|
|
7
|
-
dotenv.config();
|
|
8
|
-
async function createTenantSchemas() {
|
|
9
|
-
var _a;
|
|
10
|
-
const sourcePrisma = new client_1.PrismaClient({
|
|
11
|
-
datasources: {
|
|
12
|
-
db: {
|
|
13
|
-
url: process.env.SOURCE_DATABASE_URL,
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
const targetPrisma = new client_1.PrismaClient({
|
|
18
|
-
datasources: {
|
|
19
|
-
db: {
|
|
20
|
-
url: process.env.DATABASE_URL,
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
try {
|
|
25
|
-
console.log('Fetching API keys from source database to create tenant schemas...');
|
|
26
|
-
const apiKeys = await sourcePrisma.api_keys.findMany({
|
|
27
|
-
select: {
|
|
28
|
-
api_key: true,
|
|
29
|
-
providers: {
|
|
30
|
-
select: {
|
|
31
|
-
name: true,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
console.log(`Found ${apiKeys.length} API keys to create schemas for.`);
|
|
37
|
-
const sqlCommands = [];
|
|
38
|
-
sqlCommands.push('CREATE SCHEMA IF NOT EXISTS public;');
|
|
39
|
-
for (const apiKey of apiKeys) {
|
|
40
|
-
const schemaName = apiKey.api_key;
|
|
41
|
-
const providerName = ((_a = apiKey.providers) === null || _a === void 0 ? void 0 : _a.name) || 'unknown';
|
|
42
|
-
console.log(`Creating schema for ${providerName} with key ${schemaName}`);
|
|
43
|
-
sqlCommands.push(`CREATE SCHEMA IF NOT EXISTS "${schemaName}";`);
|
|
44
|
-
try {
|
|
45
|
-
const existingApiKey = await targetPrisma.api_keys.findUnique({
|
|
46
|
-
where: { api_key: schemaName },
|
|
47
|
-
});
|
|
48
|
-
if (!existingApiKey) {
|
|
49
|
-
console.log(`Creating API key record in target database for ${schemaName}`);
|
|
50
|
-
const sourceApiKeyFull = await sourcePrisma.api_keys.findUnique({
|
|
51
|
-
where: { api_key: schemaName },
|
|
52
|
-
include: {
|
|
53
|
-
providers: true,
|
|
54
|
-
users: true,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
if (sourceApiKeyFull) {
|
|
58
|
-
let providerId = null;
|
|
59
|
-
if (sourceApiKeyFull.provider_id) {
|
|
60
|
-
const existingProvider = await targetPrisma.providers.findUnique({
|
|
61
|
-
where: { provider_id: sourceApiKeyFull.provider_id },
|
|
62
|
-
});
|
|
63
|
-
if (!existingProvider && sourceApiKeyFull.providers) {
|
|
64
|
-
const newProvider = await targetPrisma.providers.create({
|
|
65
|
-
data: {
|
|
66
|
-
provider_id: sourceApiKeyFull.providers.provider_id,
|
|
67
|
-
name: sourceApiKeyFull.providers.name,
|
|
68
|
-
api_key: sourceApiKeyFull.providers.api_key,
|
|
69
|
-
country_id: sourceApiKeyFull.providers.country_id,
|
|
70
|
-
contact_email: sourceApiKeyFull.providers.contact_email,
|
|
71
|
-
is_active: sourceApiKeyFull.providers.is_active,
|
|
72
|
-
agreement: sourceApiKeyFull.providers.agreement,
|
|
73
|
-
image: sourceApiKeyFull.providers.image,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
providerId = newProvider.provider_id;
|
|
77
|
-
}
|
|
78
|
-
else if (existingProvider) {
|
|
79
|
-
providerId = existingProvider.provider_id;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
await targetPrisma.api_keys.create({
|
|
83
|
-
data: {
|
|
84
|
-
api_key: sourceApiKeyFull.api_key,
|
|
85
|
-
name: sourceApiKeyFull.name,
|
|
86
|
-
is_active: sourceApiKeyFull.is_active,
|
|
87
|
-
user_id: sourceApiKeyFull.user_id,
|
|
88
|
-
provider_id: providerId,
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
console.error(`Error creating API key in target database for ${schemaName}:`, error);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const migrationsDir = path.join(__dirname, '../../../prisma/migrations');
|
|
99
|
-
if (!fs.existsSync(migrationsDir)) {
|
|
100
|
-
console.log(`Creating migrations directory: ${migrationsDir}`);
|
|
101
|
-
fs.mkdirSync(migrationsDir, { recursive: true });
|
|
102
|
-
}
|
|
103
|
-
const sqlFilePath = path.join(migrationsDir, 'tenant-schemas.sql');
|
|
104
|
-
fs.writeFileSync(sqlFilePath, sqlCommands.join('\n'));
|
|
105
|
-
console.log(`SQL commands written to ${path.resolve(sqlFilePath)}`);
|
|
106
|
-
console.log('Run this SQL file against your database to create the schemas.');
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
console.error('Error creating tenant schemas:', error);
|
|
110
|
-
}
|
|
111
|
-
finally {
|
|
112
|
-
await sourcePrisma.$disconnect();
|
|
113
|
-
await targetPrisma.$disconnect();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
createTenantSchemas().catch(console.error);
|
|
117
|
-
//# sourceMappingURL=create-tenant-schemas.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-tenant-schemas.js","sourceRoot":"","sources":["../../src/scripts/create-tenant-schemas.ts"],"names":[],"mappings":";;AAAA,2CAA8C;AAC9C,yBAAyB;AACzB,6BAA6B;AAC7B,iCAAiC;AAEjC,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,KAAK,UAAU,mBAAmB;;IAEhC,MAAM,YAAY,GAAG,IAAI,qBAAY,CAAC;QACpC,WAAW,EAAE;YACX,EAAE,EAAE;gBACF,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;aACrC;SACF;KACF,CAAC,CAAC;IAGH,MAAM,YAAY,GAAG,IAAI,qBAAY,CAAC;QACpC,WAAW,EAAE;YACX,EAAE,EAAE;gBACF,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;aAC9B;SACF;KACF,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;QAGlF,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACnD,MAAM,EAAE;gBACN,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE;oBACT,MAAM,EAAE;wBACN,IAAI,EAAE,IAAI;qBACX;iBACF;aACF;SACF,CAAC,CAAC;QAEH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C,IAAI,CAAC,SAAS,EAAE,4BAA4B,CAAC,CAAC;QACzE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YAClC,OAAO,CAAC,GAAG,CAAC,kCAAkC,aAAa,EAAE,CAAC,CAAC;YAC/D,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;QAGD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC;QACnE,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAGtD,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACpE,OAAO,CAAC,GAAG,CAAC,gEAAgE,CAAC,CAAC;IAEhF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC;YAAS,CAAC;QACT,MAAM,YAAY,CAAC,WAAW,EAAE,CAAC;QACjC,MAAM,YAAY,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;AACH,CAAC;AAED,mBAAmB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SchemaUtils } from "./schema-utils";
|
|
2
|
-
import { DataTransformer } from "./data-transformer";
|
|
3
|
-
import { ColumnSchema, DatabaseConnections, MigrationOptions, TableConfig } from "./types";
|
|
4
|
-
export declare class BatchMigrator {
|
|
5
|
-
private readonly schemaUtils;
|
|
6
|
-
private readonly dataTransformer;
|
|
7
|
-
private readonly connections;
|
|
8
|
-
private readonly options;
|
|
9
|
-
private readonly providerId?;
|
|
10
|
-
private readonly logger;
|
|
11
|
-
private readonly typecastManager;
|
|
12
|
-
constructor(schemaUtils: SchemaUtils, dataTransformer: DataTransformer, connections: DatabaseConnections, options: MigrationOptions, providerId?: string | null);
|
|
13
|
-
validateSchema(sourceColumns: ColumnSchema[], targetColumns: ColumnSchema[]): Promise<void>;
|
|
14
|
-
migrateEntityDataInBatches(sourceSchema: string, targetSchema: string, tableConfig: TableConfig, tenantId: string): Promise<void>;
|
|
15
|
-
private fetchBatch;
|
|
16
|
-
private buildWhereClause;
|
|
17
|
-
private processBatchWithTransaction;
|
|
18
|
-
private transformRecord;
|
|
19
|
-
private insertRecord;
|
|
20
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BatchMigrator = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const typecast_manager_1 = require("./typecast-manager");
|
|
6
|
-
const BATCH_SIZE = 100;
|
|
7
|
-
const MAX_RETRIES = 3;
|
|
8
|
-
const RETRY_BASE_DELAY = 1000;
|
|
9
|
-
class BatchMigrator {
|
|
10
|
-
constructor(schemaUtils, dataTransformer, connections, options, providerId) {
|
|
11
|
-
this.schemaUtils = schemaUtils;
|
|
12
|
-
this.dataTransformer = dataTransformer;
|
|
13
|
-
this.connections = connections;
|
|
14
|
-
this.options = options;
|
|
15
|
-
this.providerId = providerId;
|
|
16
|
-
this.logger = new common_1.Logger("BatchMigrator");
|
|
17
|
-
this.typecastManager = new typecast_manager_1.TypecastManager();
|
|
18
|
-
}
|
|
19
|
-
async validateSchema(sourceColumns, targetColumns) {
|
|
20
|
-
for (const targetColumn of targetColumns) {
|
|
21
|
-
const sourceColumn = sourceColumns.find((col) => col.column_name === targetColumn.column_name);
|
|
22
|
-
if (!sourceColumn) {
|
|
23
|
-
if (targetColumn.is_nullable === "NO") {
|
|
24
|
-
throw new Error(`Required column ${targetColumn.column_name} not found in source schema`);
|
|
25
|
-
}
|
|
26
|
-
this.logger.warn(`Column ${targetColumn.column_name} not found in source schema but is nullable`);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (!this.typecastManager.areTypesCompatible(sourceColumn.data_type, targetColumn.data_type)) {
|
|
30
|
-
throw new Error(`Incompatible data types for column ${targetColumn.column_name}: ` +
|
|
31
|
-
`source ${sourceColumn.data_type} -> target ${targetColumn.data_type}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async migrateEntityDataInBatches(sourceSchema, targetSchema, tableConfig, tenantId) {
|
|
36
|
-
const sourceColumns = await this.schemaUtils.getTableColumns(sourceSchema, tableConfig.sourceTable);
|
|
37
|
-
const targetColumns = await this.schemaUtils.getTableColumns(targetSchema, tableConfig.targetTable);
|
|
38
|
-
await this.validateSchema(sourceColumns, targetColumns);
|
|
39
|
-
let offset = 0;
|
|
40
|
-
let hasMoreRecords = true;
|
|
41
|
-
let retryCount = 0;
|
|
42
|
-
while (hasMoreRecords) {
|
|
43
|
-
try {
|
|
44
|
-
const records = await this.fetchBatch(sourceSchema, tableConfig, offset, BATCH_SIZE);
|
|
45
|
-
if (records.length === 0) {
|
|
46
|
-
hasMoreRecords = false;
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
await this.processBatchWithTransaction(records, targetSchema, tableConfig, sourceColumns, targetColumns, tenantId);
|
|
50
|
-
offset += BATCH_SIZE;
|
|
51
|
-
retryCount = 0;
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
if (retryCount < MAX_RETRIES) {
|
|
55
|
-
retryCount++;
|
|
56
|
-
const delay = RETRY_BASE_DELAY * Math.pow(2, retryCount - 1);
|
|
57
|
-
this.logger.warn(`Error processing batch, retrying in ${delay}ms (attempt ${retryCount}/${MAX_RETRIES}): ${error.message}`);
|
|
58
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
throw new Error(`Failed to process batch after ${MAX_RETRIES} retries: ${error.message}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async fetchBatch(sourceSchema, tableConfig, offset, limit) {
|
|
67
|
-
const query = `
|
|
68
|
-
SELECT *
|
|
69
|
-
FROM "${sourceSchema}"."${tableConfig.sourceTable}"
|
|
70
|
-
${this.buildWhereClause(tableConfig)}
|
|
71
|
-
ORDER BY "${tableConfig.idField}"
|
|
72
|
-
LIMIT ${limit}
|
|
73
|
-
OFFSET ${offset}
|
|
74
|
-
`;
|
|
75
|
-
const result = await this.connections.sourcePool.query(query);
|
|
76
|
-
return result.rows;
|
|
77
|
-
}
|
|
78
|
-
buildWhereClause(tableConfig) {
|
|
79
|
-
const conditions = [];
|
|
80
|
-
if (this.providerId) {
|
|
81
|
-
conditions.push(`"${tableConfig.providerLink}" = '${this.providerId}'`);
|
|
82
|
-
}
|
|
83
|
-
if (tableConfig.filterColumn) {
|
|
84
|
-
conditions.push(`"${tableConfig.filterColumn}" IS NOT NULL`);
|
|
85
|
-
}
|
|
86
|
-
return conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
87
|
-
}
|
|
88
|
-
async processBatchWithTransaction(records, targetSchema, tableConfig, sourceColumns, targetColumns, tenantId) {
|
|
89
|
-
const client = await this.connections.targetPool.connect();
|
|
90
|
-
try {
|
|
91
|
-
await client.query("BEGIN");
|
|
92
|
-
for (const record of records) {
|
|
93
|
-
const transformedRecord = await this.transformRecord(record, sourceColumns, targetColumns, tenantId);
|
|
94
|
-
await this.insertRecord(client, targetSchema, tableConfig.targetTable, transformedRecord);
|
|
95
|
-
}
|
|
96
|
-
await client.query("COMMIT");
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
await client.query("ROLLBACK");
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
client.release();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
async transformRecord(record, sourceColumns, targetColumns, tenantId) {
|
|
107
|
-
const transformedRecord = {};
|
|
108
|
-
for (const targetColumn of targetColumns) {
|
|
109
|
-
const sourceColumn = sourceColumns.find((col) => col.column_name === targetColumn.column_name);
|
|
110
|
-
if (!sourceColumn) {
|
|
111
|
-
transformedRecord[targetColumn.column_name] = null;
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
const value = record[targetColumn.column_name];
|
|
115
|
-
transformedRecord[targetColumn.column_name] =
|
|
116
|
-
await this.dataTransformer.transformColumnValue(value, targetColumn.column_name, Object.assign(Object.assign({}, targetColumn), { source_type: sourceColumn.data_type }), tenantId);
|
|
117
|
-
}
|
|
118
|
-
return transformedRecord;
|
|
119
|
-
}
|
|
120
|
-
async insertRecord(client, schema, table, record) {
|
|
121
|
-
const columns = Object.keys(record);
|
|
122
|
-
const values = Object.values(record);
|
|
123
|
-
const placeholders = values.map((_, i) => `$${i + 1}`).join(", ");
|
|
124
|
-
const query = `
|
|
125
|
-
INSERT INTO "${schema}"."${table}"
|
|
126
|
-
(${columns.map((col) => `"${col}"`).join(", ")})
|
|
127
|
-
VALUES (${placeholders})
|
|
128
|
-
ON CONFLICT DO NOTHING
|
|
129
|
-
`;
|
|
130
|
-
await client.query(query, values);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
exports.BatchMigrator = BatchMigrator;
|
|
134
|
-
//# sourceMappingURL=batch-migrator.js.map
|