@javalabs/prisma-client 1.0.30 → 1.0.31

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.
Files changed (80) hide show
  1. package/.github/CODEOWNERS +1 -1
  2. package/README.md +269 -269
  3. package/dist/scripts/add-uuid-to-table.js +32 -32
  4. package/dist/scripts/data-migration/batch-migrator.js +12 -12
  5. package/dist/scripts/data-migration/data-transformer.js +14 -14
  6. package/dist/scripts/data-migration/dependency-resolver.js +23 -23
  7. package/dist/scripts/data-migration/entity-discovery.js +68 -68
  8. package/dist/scripts/data-migration/foreign-key-manager.js +23 -23
  9. package/dist/scripts/data-migration/migration-tool.js +5 -5
  10. package/dist/scripts/data-migration/schema-utils.js +74 -74
  11. package/dist/scripts/data-migration/typecast-manager.js +4 -4
  12. package/dist/scripts/database-initializer.js +5 -5
  13. package/dist/scripts/drop-database.js +5 -5
  14. package/dist/scripts/fix-data-types.js +53 -53
  15. package/dist/scripts/fix-enum-values.js +34 -34
  16. package/dist/scripts/fix-schema-discrepancies.js +40 -40
  17. package/dist/scripts/fix-table-indexes.js +81 -81
  18. package/dist/scripts/migrate-schema-structure.js +4 -4
  19. package/dist/scripts/migrate-uuid.js +19 -19
  20. package/dist/scripts/post-migration-validator.js +49 -49
  21. package/dist/scripts/pre-migration-validator.js +107 -107
  22. package/dist/scripts/reset-database.js +21 -21
  23. package/dist/scripts/retry-failed-migrations.js +28 -28
  24. package/dist/scripts/run-migration.js +5 -5
  25. package/dist/scripts/schema-sync.js +18 -18
  26. package/dist/scripts/sequence-sync-cli.js +55 -55
  27. package/dist/scripts/sequence-synchronizer.js +20 -20
  28. package/dist/scripts/sync-enum-types.js +30 -30
  29. package/dist/scripts/sync-enum-values.js +52 -52
  30. package/dist/scripts/truncate-database.js +10 -10
  31. package/dist/scripts/verify-migration-setup.js +10 -10
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/migration-config.json +63 -63
  34. package/migration-config.json.bk +95 -95
  35. package/migrations/add_reserved_amount.sql +7 -7
  36. package/package.json +44 -44
  37. package/prisma/migrations/add_uuid_to_transactions.sql +13 -13
  38. package/prisma/schema.prisma +636 -609
  39. package/src/index.ts +23 -23
  40. package/src/prisma-factory.service.ts +40 -40
  41. package/src/prisma.module.ts +9 -9
  42. package/src/prisma.service.ts +16 -16
  43. package/src/scripts/add-uuid-to-table.ts +138 -138
  44. package/src/scripts/create-tenant-schemas.ts +145 -145
  45. package/src/scripts/data-migration/batch-migrator.ts +248 -248
  46. package/src/scripts/data-migration/data-transformer.ts +426 -426
  47. package/src/scripts/data-migration/db-connector.ts +120 -120
  48. package/src/scripts/data-migration/dependency-resolver.ts +174 -174
  49. package/src/scripts/data-migration/entity-discovery.ts +196 -196
  50. package/src/scripts/data-migration/foreign-key-manager.ts +277 -277
  51. package/src/scripts/data-migration/migration-config.json +63 -63
  52. package/src/scripts/data-migration/migration-tool.ts +509 -509
  53. package/src/scripts/data-migration/schema-utils.ts +248 -248
  54. package/src/scripts/data-migration/tenant-migrator.ts +201 -201
  55. package/src/scripts/data-migration/typecast-manager.ts +193 -193
  56. package/src/scripts/data-migration/types.ts +113 -113
  57. package/src/scripts/database-initializer.ts +49 -49
  58. package/src/scripts/drop-database.ts +104 -104
  59. package/src/scripts/dump-source-db.sh +61 -61
  60. package/src/scripts/encrypt-user-passwords.ts +36 -36
  61. package/src/scripts/error-handler.ts +117 -117
  62. package/src/scripts/fix-data-types.ts +241 -241
  63. package/src/scripts/fix-enum-values.ts +357 -357
  64. package/src/scripts/fix-schema-discrepancies.ts +317 -317
  65. package/src/scripts/fix-table-indexes.ts +601 -601
  66. package/src/scripts/migrate-schema-structure.ts +90 -90
  67. package/src/scripts/migrate-uuid.ts +76 -76
  68. package/src/scripts/post-migration-validator.ts +526 -526
  69. package/src/scripts/pre-migration-validator.ts +610 -610
  70. package/src/scripts/reset-database.ts +263 -263
  71. package/src/scripts/retry-failed-migrations.ts +416 -416
  72. package/src/scripts/run-migration.ts +707 -707
  73. package/src/scripts/schema-sync.ts +128 -128
  74. package/src/scripts/sequence-sync-cli.ts +416 -416
  75. package/src/scripts/sequence-synchronizer.ts +127 -127
  76. package/src/scripts/sync-enum-types.ts +170 -170
  77. package/src/scripts/sync-enum-values.ts +563 -563
  78. package/src/scripts/truncate-database.ts +123 -123
  79. package/src/scripts/verify-migration-setup.ts +135 -135
  80. package/tsconfig.json +17 -17
@@ -1,118 +1,118 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { Logger } from '@nestjs/common';
4
-
5
- export class MigrationErrorHandler {
6
- private readonly logger = new Logger('MigrationErrorHandler');
7
- private errorLog: Record<string, any[]> = {};
8
- private errorLogPath: string;
9
-
10
- constructor(private readonly logDir: string = path.join(process.cwd(), 'migration-logs')) {
11
- // Crear directorio de logs si no existe
12
- if (!fs.existsSync(this.logDir)) {
13
- fs.mkdirSync(this.logDir, { recursive: true });
14
- }
15
-
16
- // Crear nombre de archivo con timestamp
17
- const timestamp = new Date().toISOString().replace(/:/g, '-').replace(/\..+/, '');
18
- this.errorLogPath = path.join(this.logDir, `migration-errors-${timestamp}.json`);
19
-
20
- // Inicializar archivo de log
21
- this.saveErrorLog();
22
- }
23
-
24
- /**
25
- * Registra un error durante la migración
26
- */
27
- logError(tenantId: string, entityName: string, recordId: any, error: Error, data?: any): void {
28
- if (!this.errorLog[tenantId]) {
29
- this.errorLog[tenantId] = [];
30
- }
31
-
32
- this.errorLog[tenantId].push({
33
- timestamp: new Date().toISOString(),
34
- entity: entityName,
35
- recordId,
36
- error: {
37
- message: error.message,
38
- stack: error.stack,
39
- },
40
- data: data || null,
41
- });
42
-
43
- // Guardar el log después de cada error
44
- this.saveErrorLog();
45
- }
46
-
47
- /**
48
- * Guarda el log de errores en un archivo JSON
49
- */
50
- private saveErrorLog(): void {
51
- try {
52
- fs.writeFileSync(
53
- this.errorLogPath,
54
- JSON.stringify(this.errorLog, null, 2),
55
- 'utf8'
56
- );
57
- } catch (error) {
58
- this.logger.error(`Error saving error log: ${error.message}`);
59
- }
60
- }
61
-
62
- /**
63
- * Genera un informe de errores
64
- */
65
- generateErrorReport(): string {
66
- let totalErrors = 0;
67
- let report = 'Migration Error Report\n';
68
- report += '=====================\n\n';
69
-
70
- for (const tenantId in this.errorLog) {
71
- const tenantErrors = this.errorLog[tenantId];
72
- if (tenantErrors.length === 0) continue;
73
-
74
- totalErrors += tenantErrors.length;
75
- report += `Tenant: ${tenantId}\n`;
76
- report += `Errors: ${tenantErrors.length}\n\n`;
77
-
78
- // Agrupar errores por entidad
79
- const entityErrors: Record<string, number> = {};
80
- for (const error of tenantErrors) {
81
- entityErrors[error.entity] = (entityErrors[error.entity] || 0) + 1;
82
- }
83
-
84
- report += 'Errors by entity:\n';
85
- for (const entity in entityErrors) {
86
- report += ` - ${entity}: ${entityErrors[entity]}\n`;
87
- }
88
- report += '\n';
89
-
90
- // Mostrar los primeros 5 errores como ejemplo
91
- report += 'Sample errors:\n';
92
- for (let i = 0; i < Math.min(5, tenantErrors.length); i++) {
93
- const error = tenantErrors[i];
94
- report += ` - ${error.entity} (ID: ${error.recordId}): ${error.error.message}\n`;
95
- }
96
- report += '\n';
97
- }
98
-
99
- report += `Total errors: ${totalErrors}\n`;
100
- report += `Full error log saved to: ${this.errorLogPath}\n`;
101
-
102
- return report;
103
- }
104
-
105
- /**
106
- * Obtiene la lista de errores para un tenant específico
107
- */
108
- getErrorsForTenant(tenantId: string): any[] {
109
- return this.errorLog[tenantId] || [];
110
- }
111
-
112
- /**
113
- * Obtiene todos los errores
114
- */
115
- getAllErrors(): Record<string, any[]> {
116
- return this.errorLog;
117
- }
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { Logger } from '@nestjs/common';
4
+
5
+ export class MigrationErrorHandler {
6
+ private readonly logger = new Logger('MigrationErrorHandler');
7
+ private errorLog: Record<string, any[]> = {};
8
+ private errorLogPath: string;
9
+
10
+ constructor(private readonly logDir: string = path.join(process.cwd(), 'migration-logs')) {
11
+ // Crear directorio de logs si no existe
12
+ if (!fs.existsSync(this.logDir)) {
13
+ fs.mkdirSync(this.logDir, { recursive: true });
14
+ }
15
+
16
+ // Crear nombre de archivo con timestamp
17
+ const timestamp = new Date().toISOString().replace(/:/g, '-').replace(/\..+/, '');
18
+ this.errorLogPath = path.join(this.logDir, `migration-errors-${timestamp}.json`);
19
+
20
+ // Inicializar archivo de log
21
+ this.saveErrorLog();
22
+ }
23
+
24
+ /**
25
+ * Registra un error durante la migración
26
+ */
27
+ logError(tenantId: string, entityName: string, recordId: any, error: Error, data?: any): void {
28
+ if (!this.errorLog[tenantId]) {
29
+ this.errorLog[tenantId] = [];
30
+ }
31
+
32
+ this.errorLog[tenantId].push({
33
+ timestamp: new Date().toISOString(),
34
+ entity: entityName,
35
+ recordId,
36
+ error: {
37
+ message: error.message,
38
+ stack: error.stack,
39
+ },
40
+ data: data || null,
41
+ });
42
+
43
+ // Guardar el log después de cada error
44
+ this.saveErrorLog();
45
+ }
46
+
47
+ /**
48
+ * Guarda el log de errores en un archivo JSON
49
+ */
50
+ private saveErrorLog(): void {
51
+ try {
52
+ fs.writeFileSync(
53
+ this.errorLogPath,
54
+ JSON.stringify(this.errorLog, null, 2),
55
+ 'utf8'
56
+ );
57
+ } catch (error) {
58
+ this.logger.error(`Error saving error log: ${error.message}`);
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Genera un informe de errores
64
+ */
65
+ generateErrorReport(): string {
66
+ let totalErrors = 0;
67
+ let report = 'Migration Error Report\n';
68
+ report += '=====================\n\n';
69
+
70
+ for (const tenantId in this.errorLog) {
71
+ const tenantErrors = this.errorLog[tenantId];
72
+ if (tenantErrors.length === 0) continue;
73
+
74
+ totalErrors += tenantErrors.length;
75
+ report += `Tenant: ${tenantId}\n`;
76
+ report += `Errors: ${tenantErrors.length}\n\n`;
77
+
78
+ // Agrupar errores por entidad
79
+ const entityErrors: Record<string, number> = {};
80
+ for (const error of tenantErrors) {
81
+ entityErrors[error.entity] = (entityErrors[error.entity] || 0) + 1;
82
+ }
83
+
84
+ report += 'Errors by entity:\n';
85
+ for (const entity in entityErrors) {
86
+ report += ` - ${entity}: ${entityErrors[entity]}\n`;
87
+ }
88
+ report += '\n';
89
+
90
+ // Mostrar los primeros 5 errores como ejemplo
91
+ report += 'Sample errors:\n';
92
+ for (let i = 0; i < Math.min(5, tenantErrors.length); i++) {
93
+ const error = tenantErrors[i];
94
+ report += ` - ${error.entity} (ID: ${error.recordId}): ${error.error.message}\n`;
95
+ }
96
+ report += '\n';
97
+ }
98
+
99
+ report += `Total errors: ${totalErrors}\n`;
100
+ report += `Full error log saved to: ${this.errorLogPath}\n`;
101
+
102
+ return report;
103
+ }
104
+
105
+ /**
106
+ * Obtiene la lista de errores para un tenant específico
107
+ */
108
+ getErrorsForTenant(tenantId: string): any[] {
109
+ return this.errorLog[tenantId] || [];
110
+ }
111
+
112
+ /**
113
+ * Obtiene todos los errores
114
+ */
115
+ getAllErrors(): Record<string, any[]> {
116
+ return this.errorLog;
117
+ }
118
118
  }