@javalabs/prisma-client 1.0.26 → 1.0.29
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/.github/CODEOWNERS +1 -1
- package/README.md +269 -269
- package/migration-config.json +63 -63
- package/migration-config.json.bk +95 -95
- package/migrations/add_reserved_amount.sql +7 -7
- package/package.json +44 -44
- package/prisma/migrations/add_uuid_to_transactions.sql +13 -13
- package/prisma/schema.prisma +609 -607
- package/src/index.ts +23 -23
- package/src/prisma-factory.service.ts +40 -40
- package/src/prisma.module.ts +9 -9
- package/src/prisma.service.ts +16 -16
- package/src/scripts/add-uuid-to-table.ts +138 -138
- package/src/scripts/create-tenant-schemas.ts +145 -145
- package/src/scripts/data-migration/batch-migrator.ts +248 -248
- package/src/scripts/data-migration/data-transformer.ts +426 -426
- package/src/scripts/data-migration/db-connector.ts +120 -120
- package/src/scripts/data-migration/dependency-resolver.ts +174 -174
- package/src/scripts/data-migration/entity-discovery.ts +196 -196
- package/src/scripts/data-migration/foreign-key-manager.ts +277 -277
- package/src/scripts/data-migration/migration-config.json +63 -63
- package/src/scripts/data-migration/migration-tool.ts +509 -509
- package/src/scripts/data-migration/schema-utils.ts +248 -248
- package/src/scripts/data-migration/tenant-migrator.ts +201 -201
- package/src/scripts/data-migration/typecast-manager.ts +193 -193
- package/src/scripts/data-migration/types.ts +113 -113
- package/src/scripts/database-initializer.ts +49 -49
- package/src/scripts/drop-database.ts +104 -104
- package/src/scripts/dump-source-db.sh +61 -61
- package/src/scripts/encrypt-user-passwords.ts +36 -36
- package/src/scripts/error-handler.ts +117 -117
- package/src/scripts/fix-data-types.ts +241 -241
- package/src/scripts/fix-enum-values.ts +357 -357
- package/src/scripts/fix-schema-discrepancies.ts +317 -317
- package/src/scripts/fix-table-indexes.ts +601 -601
- package/src/scripts/migrate-schema-structure.ts +90 -90
- package/src/scripts/migrate-uuid.ts +76 -76
- package/src/scripts/post-migration-validator.ts +526 -526
- package/src/scripts/pre-migration-validator.ts +610 -610
- package/src/scripts/reset-database.ts +263 -263
- package/src/scripts/retry-failed-migrations.ts +416 -416
- package/src/scripts/run-migration.ts +707 -707
- package/src/scripts/schema-sync.ts +128 -128
- package/src/scripts/sequence-sync-cli.ts +416 -416
- package/src/scripts/sequence-synchronizer.ts +127 -127
- package/src/scripts/sync-enum-types.ts +170 -170
- package/src/scripts/sync-enum-values.ts +563 -563
- package/src/scripts/truncate-database.ts +123 -123
- package/src/scripts/verify-migration-setup.ts +135 -135
- package/tsconfig.json +17 -17
- 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 -18
- package/prisma/migrations/add_bank_receipt_number.sql +0 -9
|
@@ -1,193 +1,193 @@
|
|
|
1
|
-
import { PrismaClient } from "@prisma/client";
|
|
2
|
-
|
|
3
|
-
export class TypecastManager {
|
|
4
|
-
private readonly prisma = new PrismaClient();
|
|
5
|
-
private readonly cache = new Map<string, Map<string, string>>(); // cache tabla -> columna -> typecast
|
|
6
|
-
|
|
7
|
-
private readonly compatibilityMap: Record<string, string[]> = {
|
|
8
|
-
integer: ["bigint", "smallint", "numeric", "decimal"],
|
|
9
|
-
bigint: ["integer", "numeric", "decimal"],
|
|
10
|
-
smallint: ["integer", "bigint", "numeric", "decimal"],
|
|
11
|
-
numeric: [
|
|
12
|
-
"integer",
|
|
13
|
-
"bigint",
|
|
14
|
-
"smallint",
|
|
15
|
-
"decimal",
|
|
16
|
-
"real",
|
|
17
|
-
"double precision",
|
|
18
|
-
],
|
|
19
|
-
decimal: [
|
|
20
|
-
"numeric",
|
|
21
|
-
"integer",
|
|
22
|
-
"bigint",
|
|
23
|
-
"smallint",
|
|
24
|
-
"real",
|
|
25
|
-
"double precision",
|
|
26
|
-
],
|
|
27
|
-
real: ["numeric", "decimal", "double precision"],
|
|
28
|
-
"double precision": ["numeric", "decimal", "real"],
|
|
29
|
-
"character varying": ["text", "char", "varchar"],
|
|
30
|
-
varchar: ["text", "character varying", "char"],
|
|
31
|
-
char: ["text", "character varying", "varchar"],
|
|
32
|
-
text: ["character varying", "varchar", "char"],
|
|
33
|
-
timestamp: [
|
|
34
|
-
"timestamptz",
|
|
35
|
-
"timestamp without time zone",
|
|
36
|
-
"timestamp with time zone",
|
|
37
|
-
],
|
|
38
|
-
timestamptz: [
|
|
39
|
-
"timestamp",
|
|
40
|
-
"timestamp without time zone",
|
|
41
|
-
"timestamp with time zone",
|
|
42
|
-
],
|
|
43
|
-
date: ["timestamp", "timestamptz"],
|
|
44
|
-
boolean: ["bool"],
|
|
45
|
-
json: ["jsonb"],
|
|
46
|
-
jsonb: ["json"],
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
async getTypecastForColumn(
|
|
50
|
-
tableName: string,
|
|
51
|
-
columnName: string
|
|
52
|
-
): Promise<string | undefined> {
|
|
53
|
-
if (!this.cache.has(tableName)) {
|
|
54
|
-
await this.loadTableSchema(tableName);
|
|
55
|
-
}
|
|
56
|
-
const tableSchema = this.cache.get(tableName);
|
|
57
|
-
return tableSchema?.get(columnName);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private async loadTableSchema(tableName: string) {
|
|
61
|
-
const columns = await this.prisma.$queryRawUnsafe<any[]>(`
|
|
62
|
-
SELECT column_name, data_type, udt_name, is_nullable
|
|
63
|
-
FROM information_schema.columns
|
|
64
|
-
WHERE table_name = '${tableName}'
|
|
65
|
-
`);
|
|
66
|
-
|
|
67
|
-
const tableSchema = new Map<string, string>();
|
|
68
|
-
|
|
69
|
-
for (const column of columns) {
|
|
70
|
-
const { column_name, data_type, udt_name, is_nullable } = column;
|
|
71
|
-
|
|
72
|
-
let typecast: string | undefined;
|
|
73
|
-
|
|
74
|
-
switch (data_type.toLowerCase()) {
|
|
75
|
-
case "timestamp with time zone":
|
|
76
|
-
case "timestamp without time zone":
|
|
77
|
-
case "timestamptz":
|
|
78
|
-
typecast = "::timestamp with time zone";
|
|
79
|
-
break;
|
|
80
|
-
case "timestamp":
|
|
81
|
-
typecast = "::timestamp";
|
|
82
|
-
break;
|
|
83
|
-
case "integer":
|
|
84
|
-
typecast = "::integer";
|
|
85
|
-
break;
|
|
86
|
-
case "bigint":
|
|
87
|
-
typecast = "::bigint";
|
|
88
|
-
break;
|
|
89
|
-
case "boolean":
|
|
90
|
-
typecast = "::boolean";
|
|
91
|
-
break;
|
|
92
|
-
case "numeric":
|
|
93
|
-
case "decimal":
|
|
94
|
-
typecast = "::numeric";
|
|
95
|
-
break;
|
|
96
|
-
case "double precision":
|
|
97
|
-
typecast = "::double precision";
|
|
98
|
-
break;
|
|
99
|
-
case "text":
|
|
100
|
-
case "character varying":
|
|
101
|
-
case "varchar":
|
|
102
|
-
typecast = "::text";
|
|
103
|
-
break;
|
|
104
|
-
case "date":
|
|
105
|
-
typecast = "::date";
|
|
106
|
-
break;
|
|
107
|
-
case "time":
|
|
108
|
-
case "time without time zone":
|
|
109
|
-
typecast = "::time";
|
|
110
|
-
break;
|
|
111
|
-
case "time with time zone":
|
|
112
|
-
typecast = "::timetz";
|
|
113
|
-
break;
|
|
114
|
-
case "json":
|
|
115
|
-
typecast = "::json";
|
|
116
|
-
break;
|
|
117
|
-
case "jsonb":
|
|
118
|
-
typecast = "::jsonb";
|
|
119
|
-
break;
|
|
120
|
-
case "uuid":
|
|
121
|
-
typecast = "::uuid";
|
|
122
|
-
break;
|
|
123
|
-
default:
|
|
124
|
-
if (udt_name.startsWith("_")) {
|
|
125
|
-
// Arrays
|
|
126
|
-
typecast = `::${udt_name.substring(1)}[]`;
|
|
127
|
-
} else if (udt_name.startsWith("enum_")) {
|
|
128
|
-
// Enums
|
|
129
|
-
typecast = `::${udt_name}`;
|
|
130
|
-
} else {
|
|
131
|
-
typecast = undefined;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
tableSchema.set(column_name, typecast);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
this.cache.set(tableName, tableSchema);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
areTypesCompatible(sourceType: string, targetType: string): boolean {
|
|
142
|
-
// Si los tipos son iguales, son compatibles
|
|
143
|
-
if (sourceType.toLowerCase() === targetType.toLowerCase()) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Verificar si el tipo fuente puede convertirse al tipo destino
|
|
148
|
-
const compatibleTypes =
|
|
149
|
-
this.compatibilityMap[sourceType.toLowerCase()] || [];
|
|
150
|
-
return compatibleTypes.includes(targetType.toLowerCase());
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
castValue(value: any, sourceType: string, targetType: string): any {
|
|
154
|
-
if (value === null || value === undefined) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
switch (targetType.toLowerCase()) {
|
|
160
|
-
case "integer":
|
|
161
|
-
case "bigint":
|
|
162
|
-
case "smallint":
|
|
163
|
-
return parseInt(value, 10);
|
|
164
|
-
case "numeric":
|
|
165
|
-
case "decimal":
|
|
166
|
-
case "real":
|
|
167
|
-
case "double precision":
|
|
168
|
-
return parseFloat(value);
|
|
169
|
-
case "boolean":
|
|
170
|
-
return Boolean(value);
|
|
171
|
-
case "json":
|
|
172
|
-
case "jsonb":
|
|
173
|
-
return typeof value === "string" ? JSON.parse(value) : value;
|
|
174
|
-
case "timestamp":
|
|
175
|
-
case "timestamptz":
|
|
176
|
-
return new Date(value).toISOString();
|
|
177
|
-
case "date":
|
|
178
|
-
return new Date(value).toISOString().split("T")[0];
|
|
179
|
-
case "text":
|
|
180
|
-
case "character varying":
|
|
181
|
-
case "varchar":
|
|
182
|
-
case "char":
|
|
183
|
-
return String(value);
|
|
184
|
-
default:
|
|
185
|
-
return value;
|
|
186
|
-
}
|
|
187
|
-
} catch (error) {
|
|
188
|
-
throw new Error(
|
|
189
|
-
`Error al convertir valor "${value}" de ${sourceType} a ${targetType}: ${error.message}`
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
1
|
+
import { PrismaClient } from "@prisma/client";
|
|
2
|
+
|
|
3
|
+
export class TypecastManager {
|
|
4
|
+
private readonly prisma = new PrismaClient();
|
|
5
|
+
private readonly cache = new Map<string, Map<string, string>>(); // cache tabla -> columna -> typecast
|
|
6
|
+
|
|
7
|
+
private readonly compatibilityMap: Record<string, string[]> = {
|
|
8
|
+
integer: ["bigint", "smallint", "numeric", "decimal"],
|
|
9
|
+
bigint: ["integer", "numeric", "decimal"],
|
|
10
|
+
smallint: ["integer", "bigint", "numeric", "decimal"],
|
|
11
|
+
numeric: [
|
|
12
|
+
"integer",
|
|
13
|
+
"bigint",
|
|
14
|
+
"smallint",
|
|
15
|
+
"decimal",
|
|
16
|
+
"real",
|
|
17
|
+
"double precision",
|
|
18
|
+
],
|
|
19
|
+
decimal: [
|
|
20
|
+
"numeric",
|
|
21
|
+
"integer",
|
|
22
|
+
"bigint",
|
|
23
|
+
"smallint",
|
|
24
|
+
"real",
|
|
25
|
+
"double precision",
|
|
26
|
+
],
|
|
27
|
+
real: ["numeric", "decimal", "double precision"],
|
|
28
|
+
"double precision": ["numeric", "decimal", "real"],
|
|
29
|
+
"character varying": ["text", "char", "varchar"],
|
|
30
|
+
varchar: ["text", "character varying", "char"],
|
|
31
|
+
char: ["text", "character varying", "varchar"],
|
|
32
|
+
text: ["character varying", "varchar", "char"],
|
|
33
|
+
timestamp: [
|
|
34
|
+
"timestamptz",
|
|
35
|
+
"timestamp without time zone",
|
|
36
|
+
"timestamp with time zone",
|
|
37
|
+
],
|
|
38
|
+
timestamptz: [
|
|
39
|
+
"timestamp",
|
|
40
|
+
"timestamp without time zone",
|
|
41
|
+
"timestamp with time zone",
|
|
42
|
+
],
|
|
43
|
+
date: ["timestamp", "timestamptz"],
|
|
44
|
+
boolean: ["bool"],
|
|
45
|
+
json: ["jsonb"],
|
|
46
|
+
jsonb: ["json"],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
async getTypecastForColumn(
|
|
50
|
+
tableName: string,
|
|
51
|
+
columnName: string
|
|
52
|
+
): Promise<string | undefined> {
|
|
53
|
+
if (!this.cache.has(tableName)) {
|
|
54
|
+
await this.loadTableSchema(tableName);
|
|
55
|
+
}
|
|
56
|
+
const tableSchema = this.cache.get(tableName);
|
|
57
|
+
return tableSchema?.get(columnName);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private async loadTableSchema(tableName: string) {
|
|
61
|
+
const columns = await this.prisma.$queryRawUnsafe<any[]>(`
|
|
62
|
+
SELECT column_name, data_type, udt_name, is_nullable
|
|
63
|
+
FROM information_schema.columns
|
|
64
|
+
WHERE table_name = '${tableName}'
|
|
65
|
+
`);
|
|
66
|
+
|
|
67
|
+
const tableSchema = new Map<string, string>();
|
|
68
|
+
|
|
69
|
+
for (const column of columns) {
|
|
70
|
+
const { column_name, data_type, udt_name, is_nullable } = column;
|
|
71
|
+
|
|
72
|
+
let typecast: string | undefined;
|
|
73
|
+
|
|
74
|
+
switch (data_type.toLowerCase()) {
|
|
75
|
+
case "timestamp with time zone":
|
|
76
|
+
case "timestamp without time zone":
|
|
77
|
+
case "timestamptz":
|
|
78
|
+
typecast = "::timestamp with time zone";
|
|
79
|
+
break;
|
|
80
|
+
case "timestamp":
|
|
81
|
+
typecast = "::timestamp";
|
|
82
|
+
break;
|
|
83
|
+
case "integer":
|
|
84
|
+
typecast = "::integer";
|
|
85
|
+
break;
|
|
86
|
+
case "bigint":
|
|
87
|
+
typecast = "::bigint";
|
|
88
|
+
break;
|
|
89
|
+
case "boolean":
|
|
90
|
+
typecast = "::boolean";
|
|
91
|
+
break;
|
|
92
|
+
case "numeric":
|
|
93
|
+
case "decimal":
|
|
94
|
+
typecast = "::numeric";
|
|
95
|
+
break;
|
|
96
|
+
case "double precision":
|
|
97
|
+
typecast = "::double precision";
|
|
98
|
+
break;
|
|
99
|
+
case "text":
|
|
100
|
+
case "character varying":
|
|
101
|
+
case "varchar":
|
|
102
|
+
typecast = "::text";
|
|
103
|
+
break;
|
|
104
|
+
case "date":
|
|
105
|
+
typecast = "::date";
|
|
106
|
+
break;
|
|
107
|
+
case "time":
|
|
108
|
+
case "time without time zone":
|
|
109
|
+
typecast = "::time";
|
|
110
|
+
break;
|
|
111
|
+
case "time with time zone":
|
|
112
|
+
typecast = "::timetz";
|
|
113
|
+
break;
|
|
114
|
+
case "json":
|
|
115
|
+
typecast = "::json";
|
|
116
|
+
break;
|
|
117
|
+
case "jsonb":
|
|
118
|
+
typecast = "::jsonb";
|
|
119
|
+
break;
|
|
120
|
+
case "uuid":
|
|
121
|
+
typecast = "::uuid";
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
if (udt_name.startsWith("_")) {
|
|
125
|
+
// Arrays
|
|
126
|
+
typecast = `::${udt_name.substring(1)}[]`;
|
|
127
|
+
} else if (udt_name.startsWith("enum_")) {
|
|
128
|
+
// Enums
|
|
129
|
+
typecast = `::${udt_name}`;
|
|
130
|
+
} else {
|
|
131
|
+
typecast = undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
tableSchema.set(column_name, typecast);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this.cache.set(tableName, tableSchema);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
areTypesCompatible(sourceType: string, targetType: string): boolean {
|
|
142
|
+
// Si los tipos son iguales, son compatibles
|
|
143
|
+
if (sourceType.toLowerCase() === targetType.toLowerCase()) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Verificar si el tipo fuente puede convertirse al tipo destino
|
|
148
|
+
const compatibleTypes =
|
|
149
|
+
this.compatibilityMap[sourceType.toLowerCase()] || [];
|
|
150
|
+
return compatibleTypes.includes(targetType.toLowerCase());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
castValue(value: any, sourceType: string, targetType: string): any {
|
|
154
|
+
if (value === null || value === undefined) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
switch (targetType.toLowerCase()) {
|
|
160
|
+
case "integer":
|
|
161
|
+
case "bigint":
|
|
162
|
+
case "smallint":
|
|
163
|
+
return parseInt(value, 10);
|
|
164
|
+
case "numeric":
|
|
165
|
+
case "decimal":
|
|
166
|
+
case "real":
|
|
167
|
+
case "double precision":
|
|
168
|
+
return parseFloat(value);
|
|
169
|
+
case "boolean":
|
|
170
|
+
return Boolean(value);
|
|
171
|
+
case "json":
|
|
172
|
+
case "jsonb":
|
|
173
|
+
return typeof value === "string" ? JSON.parse(value) : value;
|
|
174
|
+
case "timestamp":
|
|
175
|
+
case "timestamptz":
|
|
176
|
+
return new Date(value).toISOString();
|
|
177
|
+
case "date":
|
|
178
|
+
return new Date(value).toISOString().split("T")[0];
|
|
179
|
+
case "text":
|
|
180
|
+
case "character varying":
|
|
181
|
+
case "varchar":
|
|
182
|
+
case "char":
|
|
183
|
+
return String(value);
|
|
184
|
+
default:
|
|
185
|
+
return value;
|
|
186
|
+
}
|
|
187
|
+
} catch (error) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`Error al convertir valor "${value}" de ${sourceType} a ${targetType}: ${error.message}`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import { Pool } from "pg";
|
|
2
|
-
import { PrismaClient } from "@prisma/client";
|
|
3
|
-
|
|
4
|
-
export interface DatabaseConnection {
|
|
5
|
-
pool?: Pool;
|
|
6
|
-
prisma?: PrismaClient;
|
|
7
|
-
query: (sql: string, params?: any[]) => Promise<any>;
|
|
8
|
-
sourceId: string; // Identificador único para la fuente (ej: "colombia", "rd", "guatemala")
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface DatabaseConnections {
|
|
12
|
-
sourceConnections?: DatabaseConnection[];
|
|
13
|
-
sourcePool?: Pool;
|
|
14
|
-
targetPool: Pool;
|
|
15
|
-
targetPrisma: PrismaClient;
|
|
16
|
-
sourcePrisma?: PrismaClient;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ColumnSchema {
|
|
20
|
-
table_name: string;
|
|
21
|
-
column_name: string;
|
|
22
|
-
data_type: string;
|
|
23
|
-
udt_name: string;
|
|
24
|
-
character_maximum_length?: number;
|
|
25
|
-
is_nullable: string;
|
|
26
|
-
column_default?: string;
|
|
27
|
-
constraint_type?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Updated EntityType to include filter configuration
|
|
31
|
-
export interface EntityType {
|
|
32
|
-
name: string; // Table name
|
|
33
|
-
idField: string; // Primary key column name
|
|
34
|
-
filterColumn?: string; // Column used for filtering (either directly or via join)
|
|
35
|
-
filterVia?: string; // Intermediate table for filtering join (if needed)
|
|
36
|
-
// Keep optional legacy fields for potential backward compatibility or specific use cases
|
|
37
|
-
foreignKey?: string;
|
|
38
|
-
joinTable?: string;
|
|
39
|
-
joinField?: string;
|
|
40
|
-
joinForeignKey?: string;
|
|
41
|
-
directQuery?: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface EnumCastValue {
|
|
45
|
-
needsEnumCast: boolean;
|
|
46
|
-
value: any;
|
|
47
|
-
enumType: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface MigrationOptions {
|
|
51
|
-
publicOnly?: boolean;
|
|
52
|
-
multiTenant?: boolean;
|
|
53
|
-
sourceSchema?: string;
|
|
54
|
-
targetSchema?: string;
|
|
55
|
-
forceSingleTenant?: boolean;
|
|
56
|
-
configPath?: string;
|
|
57
|
-
batchSize?: number;
|
|
58
|
-
retryAttempts?: number;
|
|
59
|
-
validateData?: boolean;
|
|
60
|
-
logLevel?: "debug" | "info" | "warn" | "error";
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface ColumnConfig {
|
|
64
|
-
sourceColumn?: string;
|
|
65
|
-
targetColumn?: string;
|
|
66
|
-
type?: string;
|
|
67
|
-
nullable?: boolean;
|
|
68
|
-
defaultValue?: any;
|
|
69
|
-
transform?: (value: any) => any;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface TableConfig {
|
|
73
|
-
type: "public" | "filteredPublic" | "tenantInfo" | "tenant";
|
|
74
|
-
idField: string;
|
|
75
|
-
filterColumn?: string;
|
|
76
|
-
via?: string;
|
|
77
|
-
providerLink?: string;
|
|
78
|
-
tenantKey?: string;
|
|
79
|
-
dependencies?: string[];
|
|
80
|
-
sourceTable?: string;
|
|
81
|
-
targetTable?: string;
|
|
82
|
-
columns?: Record<string, ColumnConfig>;
|
|
83
|
-
skipIfExists?: boolean;
|
|
84
|
-
batchSize?: number;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface ExtendedTableConfig extends TableConfig {
|
|
88
|
-
processed?: boolean;
|
|
89
|
-
retryCount?: number;
|
|
90
|
-
lastError?: Error;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface ExtendedMigrationConfig {
|
|
94
|
-
tables: Record<string, ExtendedTableConfig>;
|
|
95
|
-
version: string;
|
|
96
|
-
sourceSchema?: string;
|
|
97
|
-
targetSchema?: string;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export interface MigrationConfig {
|
|
101
|
-
commonSchema: string;
|
|
102
|
-
tables: Record<string, TableConfig>;
|
|
103
|
-
tenantInfo: {
|
|
104
|
-
sourceTable: string;
|
|
105
|
-
tenantIdColumn: string;
|
|
106
|
-
providerIdColumn: string;
|
|
107
|
-
};
|
|
108
|
-
migrationPriorities?: {
|
|
109
|
-
high?: string[];
|
|
110
|
-
medium?: string[];
|
|
111
|
-
low?: string[];
|
|
112
|
-
};
|
|
113
|
-
}
|
|
1
|
+
import { Pool } from "pg";
|
|
2
|
+
import { PrismaClient } from "@prisma/client";
|
|
3
|
+
|
|
4
|
+
export interface DatabaseConnection {
|
|
5
|
+
pool?: Pool;
|
|
6
|
+
prisma?: PrismaClient;
|
|
7
|
+
query: (sql: string, params?: any[]) => Promise<any>;
|
|
8
|
+
sourceId: string; // Identificador único para la fuente (ej: "colombia", "rd", "guatemala")
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface DatabaseConnections {
|
|
12
|
+
sourceConnections?: DatabaseConnection[];
|
|
13
|
+
sourcePool?: Pool;
|
|
14
|
+
targetPool: Pool;
|
|
15
|
+
targetPrisma: PrismaClient;
|
|
16
|
+
sourcePrisma?: PrismaClient;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ColumnSchema {
|
|
20
|
+
table_name: string;
|
|
21
|
+
column_name: string;
|
|
22
|
+
data_type: string;
|
|
23
|
+
udt_name: string;
|
|
24
|
+
character_maximum_length?: number;
|
|
25
|
+
is_nullable: string;
|
|
26
|
+
column_default?: string;
|
|
27
|
+
constraint_type?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Updated EntityType to include filter configuration
|
|
31
|
+
export interface EntityType {
|
|
32
|
+
name: string; // Table name
|
|
33
|
+
idField: string; // Primary key column name
|
|
34
|
+
filterColumn?: string; // Column used for filtering (either directly or via join)
|
|
35
|
+
filterVia?: string; // Intermediate table for filtering join (if needed)
|
|
36
|
+
// Keep optional legacy fields for potential backward compatibility or specific use cases
|
|
37
|
+
foreignKey?: string;
|
|
38
|
+
joinTable?: string;
|
|
39
|
+
joinField?: string;
|
|
40
|
+
joinForeignKey?: string;
|
|
41
|
+
directQuery?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface EnumCastValue {
|
|
45
|
+
needsEnumCast: boolean;
|
|
46
|
+
value: any;
|
|
47
|
+
enumType: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface MigrationOptions {
|
|
51
|
+
publicOnly?: boolean;
|
|
52
|
+
multiTenant?: boolean;
|
|
53
|
+
sourceSchema?: string;
|
|
54
|
+
targetSchema?: string;
|
|
55
|
+
forceSingleTenant?: boolean;
|
|
56
|
+
configPath?: string;
|
|
57
|
+
batchSize?: number;
|
|
58
|
+
retryAttempts?: number;
|
|
59
|
+
validateData?: boolean;
|
|
60
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ColumnConfig {
|
|
64
|
+
sourceColumn?: string;
|
|
65
|
+
targetColumn?: string;
|
|
66
|
+
type?: string;
|
|
67
|
+
nullable?: boolean;
|
|
68
|
+
defaultValue?: any;
|
|
69
|
+
transform?: (value: any) => any;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface TableConfig {
|
|
73
|
+
type: "public" | "filteredPublic" | "tenantInfo" | "tenant";
|
|
74
|
+
idField: string;
|
|
75
|
+
filterColumn?: string;
|
|
76
|
+
via?: string;
|
|
77
|
+
providerLink?: string;
|
|
78
|
+
tenantKey?: string;
|
|
79
|
+
dependencies?: string[];
|
|
80
|
+
sourceTable?: string;
|
|
81
|
+
targetTable?: string;
|
|
82
|
+
columns?: Record<string, ColumnConfig>;
|
|
83
|
+
skipIfExists?: boolean;
|
|
84
|
+
batchSize?: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface ExtendedTableConfig extends TableConfig {
|
|
88
|
+
processed?: boolean;
|
|
89
|
+
retryCount?: number;
|
|
90
|
+
lastError?: Error;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface ExtendedMigrationConfig {
|
|
94
|
+
tables: Record<string, ExtendedTableConfig>;
|
|
95
|
+
version: string;
|
|
96
|
+
sourceSchema?: string;
|
|
97
|
+
targetSchema?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface MigrationConfig {
|
|
101
|
+
commonSchema: string;
|
|
102
|
+
tables: Record<string, TableConfig>;
|
|
103
|
+
tenantInfo: {
|
|
104
|
+
sourceTable: string;
|
|
105
|
+
tenantIdColumn: string;
|
|
106
|
+
providerIdColumn: string;
|
|
107
|
+
};
|
|
108
|
+
migrationPriorities?: {
|
|
109
|
+
high?: string[];
|
|
110
|
+
medium?: string[];
|
|
111
|
+
low?: string[];
|
|
112
|
+
};
|
|
113
|
+
}
|