@javalabs/prisma-client 1.0.18 → 1.0.19
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/.dockerignore +14 -0
- package/Dockerfile +23 -0
- package/README.md +269 -269
- package/dist/index.d.ts +1 -1
- package/dist/prisma.service.d.ts +1 -1
- package/dist/scripts/add-uuid-to-table.js +32 -32
- package/dist/scripts/data-migration/batch-migrator.js +12 -12
- package/dist/scripts/data-migration/data-transformer.js +14 -14
- package/dist/scripts/data-migration/dependency-resolver.js +23 -23
- package/dist/scripts/data-migration/entity-discovery.js +68 -68
- package/dist/scripts/data-migration/foreign-key-manager.js +23 -23
- package/dist/scripts/data-migration/migration-tool.js +5 -5
- package/dist/scripts/data-migration/schema-utils.js +74 -74
- package/dist/scripts/data-migration/typecast-manager.js +4 -4
- package/dist/scripts/database-initializer.js +5 -5
- package/dist/scripts/drop-database.js +5 -5
- package/dist/scripts/fix-data-types.js +53 -53
- package/dist/scripts/fix-enum-values.js +34 -34
- package/dist/scripts/fix-schema-discrepancies.js +40 -40
- package/dist/scripts/fix-table-indexes.js +81 -81
- package/dist/scripts/migrate-schema-structure.js +4 -4
- package/dist/scripts/migrate-uuid.js +19 -19
- package/dist/scripts/post-migration-validator.js +49 -49
- package/dist/scripts/pre-migration-validator.js +107 -107
- package/dist/scripts/reset-database.js +21 -21
- package/dist/scripts/retry-failed-migrations.js +28 -28
- package/dist/scripts/run-migration.js +5 -5
- package/dist/scripts/schema-sync.js +18 -18
- package/dist/scripts/sequence-sync-cli.js +55 -55
- package/dist/scripts/sequence-synchronizer.js +20 -20
- package/dist/scripts/sync-enum-types.js +30 -30
- package/dist/scripts/sync-enum-values.js +52 -52
- package/dist/scripts/truncate-database.js +10 -10
- package/dist/scripts/verify-migration-setup.js +10 -10
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migration-config.json +63 -63
- package/migration-config.json.bk +95 -95
- package/package.json +44 -44
- package/prisma/migrations/add_accepts_partial_payments_to_users.sql +19 -0
- package/prisma/migrations/add_amount_received_to_manual_payments.sql +19 -0
- package/prisma/migrations/add_commission_fields.sql +33 -0
- package/prisma/migrations/add_uuid_to_transactions.sql +13 -13
- package/prisma/migrations/complete_partial_payments_migration.sql +53 -0
- package/prisma/migrations/create_settlements_table.sql +60 -0
- package/prisma/schema.prisma +47 -1
- 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/scripts/data-migration/dependency-manager.d.ts +0 -9
- package/dist/scripts/data-migration/dependency-manager.js +0 -86
- package/dist/scripts/data-migration/dependency-manager.js.map +0 -1
- package/dist/scripts/data-migration/migration-config.json +0 -63
- package/dist/scripts/data-migration/migration-phases.d.ts +0 -5
- package/dist/scripts/data-migration/migration-phases.js +0 -55
- package/dist/scripts/data-migration/migration-phases.js.map +0 -1
- package/dist/scripts/data-migration/multi-source-migrator.d.ts +0 -17
- package/dist/scripts/data-migration/multi-source-migrator.js +0 -130
- package/dist/scripts/data-migration/multi-source-migrator.js.map +0 -1
- package/dist/scripts/data-migration/phase-generator.d.ts +0 -15
- package/dist/scripts/data-migration/phase-generator.js +0 -187
- package/dist/scripts/data-migration/phase-generator.js.map +0 -1
- package/dist/scripts/data-migration.d.ts +0 -22
- package/dist/scripts/data-migration.js +0 -593
- package/dist/scripts/data-migration.js.map +0 -1
- package/dist/scripts/multi-db-migration.d.ts +0 -1
- package/dist/scripts/multi-db-migration.js +0 -55
- package/dist/scripts/multi-db-migration.js.map +0 -1
|
@@ -44,11 +44,11 @@ class TableIndexFixer {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
async getSchemas() {
|
|
47
|
-
const result = await this.targetPool.query(`
|
|
48
|
-
SELECT schema_name
|
|
49
|
-
FROM information_schema.schemata
|
|
50
|
-
WHERE schema_name NOT IN ('information_schema', 'pg_catalog', 'pg_toast')
|
|
51
|
-
AND schema_name NOT LIKE 'pg_%'
|
|
47
|
+
const result = await this.targetPool.query(`
|
|
48
|
+
SELECT schema_name
|
|
49
|
+
FROM information_schema.schemata
|
|
50
|
+
WHERE schema_name NOT IN ('information_schema', 'pg_catalog', 'pg_toast')
|
|
51
|
+
AND schema_name NOT LIKE 'pg_%'
|
|
52
52
|
`);
|
|
53
53
|
return result.rows.map(row => row.schema_name);
|
|
54
54
|
}
|
|
@@ -66,11 +66,11 @@ class TableIndexFixer {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
async getTablesForSchema(schema) {
|
|
69
|
-
const result = await this.targetPool.query(`
|
|
70
|
-
SELECT table_name
|
|
71
|
-
FROM information_schema.tables
|
|
72
|
-
WHERE table_schema = $1
|
|
73
|
-
AND table_type = 'BASE TABLE'
|
|
69
|
+
const result = await this.targetPool.query(`
|
|
70
|
+
SELECT table_name
|
|
71
|
+
FROM information_schema.tables
|
|
72
|
+
WHERE table_schema = $1
|
|
73
|
+
AND table_type = 'BASE TABLE'
|
|
74
74
|
`, [schema]);
|
|
75
75
|
return result.rows.map(row => row.table_name);
|
|
76
76
|
}
|
|
@@ -126,24 +126,24 @@ class TableIndexFixer {
|
|
|
126
126
|
async fixUserTableSequences(schema, table) {
|
|
127
127
|
var _a;
|
|
128
128
|
try {
|
|
129
|
-
const columnsQuery = `
|
|
130
|
-
SELECT column_name
|
|
131
|
-
FROM information_schema.columns
|
|
132
|
-
WHERE table_schema = $1
|
|
133
|
-
AND table_name = $2
|
|
134
|
-
AND (is_identity = 'YES' OR column_default LIKE 'nextval%')
|
|
129
|
+
const columnsQuery = `
|
|
130
|
+
SELECT column_name
|
|
131
|
+
FROM information_schema.columns
|
|
132
|
+
WHERE table_schema = $1
|
|
133
|
+
AND table_name = $2
|
|
134
|
+
AND (is_identity = 'YES' OR column_default LIKE 'nextval%')
|
|
135
135
|
`;
|
|
136
136
|
const columnsResult = await this.targetPool.query(columnsQuery, [schema, table]);
|
|
137
137
|
const identityColumns = columnsResult.rows.map(row => row.column_name);
|
|
138
138
|
for (const column of identityColumns) {
|
|
139
|
-
const sequenceQuery = `
|
|
140
|
-
SELECT pg_get_serial_sequence($1, $2) AS sequence_name
|
|
139
|
+
const sequenceQuery = `
|
|
140
|
+
SELECT pg_get_serial_sequence($1, $2) AS sequence_name
|
|
141
141
|
`;
|
|
142
142
|
const sequenceResult = await this.targetPool.query(sequenceQuery, [`${schema}.${table}`, column]);
|
|
143
143
|
const sequenceName = (_a = sequenceResult.rows[0]) === null || _a === void 0 ? void 0 : _a.sequence_name;
|
|
144
144
|
if (sequenceName) {
|
|
145
|
-
const resetQuery = `
|
|
146
|
-
SELECT setval($1, COALESCE((SELECT MAX(${column}) FROM ${schema}.${table}), 0) + 1, true)
|
|
145
|
+
const resetQuery = `
|
|
146
|
+
SELECT setval($1, COALESCE((SELECT MAX(${column}) FROM ${schema}.${table}), 0) + 1, true)
|
|
147
147
|
`;
|
|
148
148
|
await this.targetPool.query(resetQuery, [sequenceName]);
|
|
149
149
|
this.logger.log(`Restablecida secuencia ${sequenceName} para la columna ${column} en ${schema}.${table} (tabla de usuarios)`);
|
|
@@ -210,24 +210,24 @@ class TableIndexFixer {
|
|
|
210
210
|
async fixSequences(schema, table) {
|
|
211
211
|
var _a;
|
|
212
212
|
try {
|
|
213
|
-
const columnsQuery = `
|
|
214
|
-
SELECT column_name
|
|
215
|
-
FROM information_schema.columns
|
|
216
|
-
WHERE table_schema = $1
|
|
217
|
-
AND table_name = $2
|
|
218
|
-
AND (is_identity = 'YES' OR column_default LIKE 'nextval%')
|
|
213
|
+
const columnsQuery = `
|
|
214
|
+
SELECT column_name
|
|
215
|
+
FROM information_schema.columns
|
|
216
|
+
WHERE table_schema = $1
|
|
217
|
+
AND table_name = $2
|
|
218
|
+
AND (is_identity = 'YES' OR column_default LIKE 'nextval%')
|
|
219
219
|
`;
|
|
220
220
|
const columnsResult = await this.targetPool.query(columnsQuery, [schema, table]);
|
|
221
221
|
const identityColumns = columnsResult.rows.map(row => row.column_name);
|
|
222
222
|
for (const column of identityColumns) {
|
|
223
|
-
const sequenceQuery = `
|
|
224
|
-
SELECT pg_get_serial_sequence($1, $2) AS sequence_name
|
|
223
|
+
const sequenceQuery = `
|
|
224
|
+
SELECT pg_get_serial_sequence($1, $2) AS sequence_name
|
|
225
225
|
`;
|
|
226
226
|
const sequenceResult = await this.targetPool.query(sequenceQuery, [`${schema}.${table}`, column]);
|
|
227
227
|
const sequenceName = (_a = sequenceResult.rows[0]) === null || _a === void 0 ? void 0 : _a.sequence_name;
|
|
228
228
|
if (sequenceName) {
|
|
229
|
-
const resetQuery = `
|
|
230
|
-
SELECT setval($1, COALESCE((SELECT MAX(${column}) FROM ${schema}.${table}), 0) + 1, true)
|
|
229
|
+
const resetQuery = `
|
|
230
|
+
SELECT setval($1, COALESCE((SELECT MAX(${column}) FROM ${schema}.${table}), 0) + 1, true)
|
|
231
231
|
`;
|
|
232
232
|
await this.targetPool.query(resetQuery, [sequenceName]);
|
|
233
233
|
this.logger.log(`Restablecida secuencia ${sequenceName} para la columna ${column} en ${schema}.${table}`);
|
|
@@ -249,14 +249,14 @@ class TableIndexFixer {
|
|
|
249
249
|
async getTableInfo(schema, table) {
|
|
250
250
|
var _a;
|
|
251
251
|
try {
|
|
252
|
-
const identityQuery = `
|
|
253
|
-
SELECT EXISTS (
|
|
254
|
-
SELECT 1
|
|
255
|
-
FROM information_schema.columns
|
|
256
|
-
WHERE table_schema = $1
|
|
257
|
-
AND table_name = $2
|
|
258
|
-
AND is_identity = 'YES'
|
|
259
|
-
) AS has_identity_column;
|
|
252
|
+
const identityQuery = `
|
|
253
|
+
SELECT EXISTS (
|
|
254
|
+
SELECT 1
|
|
255
|
+
FROM information_schema.columns
|
|
256
|
+
WHERE table_schema = $1
|
|
257
|
+
AND table_name = $2
|
|
258
|
+
AND is_identity = 'YES'
|
|
259
|
+
) AS has_identity_column;
|
|
260
260
|
`;
|
|
261
261
|
const result = await this.targetPool.query(identityQuery, [schema, table]);
|
|
262
262
|
return {
|
|
@@ -269,26 +269,26 @@ class TableIndexFixer {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
async getTableIndexes(pool, schema, table) {
|
|
272
|
-
const query = `
|
|
273
|
-
SELECT
|
|
274
|
-
i.relname AS index_name,
|
|
275
|
-
array_agg(a.attname) AS column_names,
|
|
276
|
-
ix.indisunique AS is_unique,
|
|
277
|
-
ix.indisprimary AS is_primary,
|
|
278
|
-
pg_get_indexdef(ix.indexrelid) AS definition
|
|
279
|
-
FROM
|
|
280
|
-
pg_index ix
|
|
281
|
-
JOIN pg_class i ON i.oid = ix.indexrelid
|
|
282
|
-
JOIN pg_class t ON t.oid = ix.indrelid
|
|
283
|
-
JOIN pg_namespace n ON n.oid = t.relnamespace
|
|
284
|
-
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
|
|
285
|
-
WHERE
|
|
286
|
-
n.nspname = $1
|
|
287
|
-
AND t.relname = $2
|
|
288
|
-
GROUP BY
|
|
289
|
-
i.relname, ix.indisunique, ix.indisprimary, ix.indexrelid
|
|
290
|
-
ORDER BY
|
|
291
|
-
i.relname;
|
|
272
|
+
const query = `
|
|
273
|
+
SELECT
|
|
274
|
+
i.relname AS index_name,
|
|
275
|
+
array_agg(a.attname) AS column_names,
|
|
276
|
+
ix.indisunique AS is_unique,
|
|
277
|
+
ix.indisprimary AS is_primary,
|
|
278
|
+
pg_get_indexdef(ix.indexrelid) AS definition
|
|
279
|
+
FROM
|
|
280
|
+
pg_index ix
|
|
281
|
+
JOIN pg_class i ON i.oid = ix.indexrelid
|
|
282
|
+
JOIN pg_class t ON t.oid = ix.indrelid
|
|
283
|
+
JOIN pg_namespace n ON n.oid = t.relnamespace
|
|
284
|
+
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
|
|
285
|
+
WHERE
|
|
286
|
+
n.nspname = $1
|
|
287
|
+
AND t.relname = $2
|
|
288
|
+
GROUP BY
|
|
289
|
+
i.relname, ix.indisunique, ix.indisprimary, ix.indexrelid
|
|
290
|
+
ORDER BY
|
|
291
|
+
i.relname;
|
|
292
292
|
`;
|
|
293
293
|
try {
|
|
294
294
|
const result = await pool.query(query, [schema, table]);
|
|
@@ -367,35 +367,35 @@ class TableIndexFixer {
|
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
async getTableColumns(schema, table) {
|
|
370
|
-
const query = `
|
|
371
|
-
SELECT column_name, data_type, is_nullable
|
|
372
|
-
FROM information_schema.columns
|
|
373
|
-
WHERE table_schema = $1
|
|
374
|
-
AND table_name = $2
|
|
370
|
+
const query = `
|
|
371
|
+
SELECT column_name, data_type, is_nullable
|
|
372
|
+
FROM information_schema.columns
|
|
373
|
+
WHERE table_schema = $1
|
|
374
|
+
AND table_name = $2
|
|
375
375
|
`;
|
|
376
376
|
const result = await this.targetPool.query(query, [schema, table]);
|
|
377
377
|
return result.rows;
|
|
378
378
|
}
|
|
379
379
|
async fixForeignKeyIndexes(schema, table) {
|
|
380
380
|
try {
|
|
381
|
-
const fkQuery = `
|
|
382
|
-
SELECT
|
|
383
|
-
kcu.column_name,
|
|
384
|
-
ccu.table_schema AS foreign_table_schema,
|
|
385
|
-
ccu.table_name AS foreign_table_name,
|
|
386
|
-
ccu.column_name AS foreign_column_name
|
|
387
|
-
FROM
|
|
388
|
-
information_schema.table_constraints AS tc
|
|
389
|
-
JOIN information_schema.key_column_usage AS kcu
|
|
390
|
-
ON tc.constraint_name = kcu.constraint_name
|
|
391
|
-
AND tc.table_schema = kcu.table_schema
|
|
392
|
-
JOIN information_schema.constraint_column_usage AS ccu
|
|
393
|
-
ON ccu.constraint_name = tc.constraint_name
|
|
394
|
-
AND ccu.table_schema = tc.table_schema
|
|
395
|
-
WHERE
|
|
396
|
-
tc.constraint_type = 'FOREIGN KEY'
|
|
397
|
-
AND tc.table_schema = $1
|
|
398
|
-
AND tc.table_name = $2;
|
|
381
|
+
const fkQuery = `
|
|
382
|
+
SELECT
|
|
383
|
+
kcu.column_name,
|
|
384
|
+
ccu.table_schema AS foreign_table_schema,
|
|
385
|
+
ccu.table_name AS foreign_table_name,
|
|
386
|
+
ccu.column_name AS foreign_column_name
|
|
387
|
+
FROM
|
|
388
|
+
information_schema.table_constraints AS tc
|
|
389
|
+
JOIN information_schema.key_column_usage AS kcu
|
|
390
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
391
|
+
AND tc.table_schema = kcu.table_schema
|
|
392
|
+
JOIN information_schema.constraint_column_usage AS ccu
|
|
393
|
+
ON ccu.constraint_name = tc.constraint_name
|
|
394
|
+
AND ccu.table_schema = tc.table_schema
|
|
395
|
+
WHERE
|
|
396
|
+
tc.constraint_type = 'FOREIGN KEY'
|
|
397
|
+
AND tc.table_schema = $1
|
|
398
|
+
AND tc.table_name = $2;
|
|
399
399
|
`;
|
|
400
400
|
const fkResult = await this.targetPool.query(fkQuery, [schema, table]);
|
|
401
401
|
const existingIndexes = await this.getTableIndexes(this.targetPool, schema, table);
|
|
@@ -57,10 +57,10 @@ async function migrateSchemaStructure() {
|
|
|
57
57
|
async function checkSchemaExists(schemaName) {
|
|
58
58
|
const prisma = new client_1.PrismaClient();
|
|
59
59
|
try {
|
|
60
|
-
const result = await prisma.$queryRaw `
|
|
61
|
-
SELECT schema_name
|
|
62
|
-
FROM information_schema.schemata
|
|
63
|
-
WHERE schema_name = ${schemaName}
|
|
60
|
+
const result = await prisma.$queryRaw `
|
|
61
|
+
SELECT schema_name
|
|
62
|
+
FROM information_schema.schemata
|
|
63
|
+
WHERE schema_name = ${schemaName}
|
|
64
64
|
`;
|
|
65
65
|
return Array.isArray(result) && result.length > 0;
|
|
66
66
|
}
|
|
@@ -9,37 +9,37 @@ async function migrateUuid() {
|
|
|
9
9
|
console.log("\n📦 Habilitando extensión uuid-ossp...");
|
|
10
10
|
await prisma.$executeRaw `CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`;
|
|
11
11
|
console.log("\n🔍 Verificando registros sin UUID...");
|
|
12
|
-
const nullUuids = await prisma.$queryRaw `
|
|
13
|
-
SELECT COUNT(*) as count
|
|
14
|
-
FROM transactions
|
|
15
|
-
WHERE uuid IS NULL;
|
|
12
|
+
const nullUuids = await prisma.$queryRaw `
|
|
13
|
+
SELECT COUNT(*) as count
|
|
14
|
+
FROM transactions
|
|
15
|
+
WHERE uuid IS NULL;
|
|
16
16
|
`;
|
|
17
17
|
if (nullUuids[0].count > 0) {
|
|
18
18
|
console.log(`\n📝 Actualizando ${nullUuids[0].count} registros sin UUID...`);
|
|
19
|
-
await prisma.$executeRaw `
|
|
20
|
-
UPDATE transactions
|
|
21
|
-
SET uuid = uuid_generate_v4()
|
|
22
|
-
WHERE uuid IS NULL;
|
|
19
|
+
await prisma.$executeRaw `
|
|
20
|
+
UPDATE transactions
|
|
21
|
+
SET uuid = uuid_generate_v4()
|
|
22
|
+
WHERE uuid IS NULL;
|
|
23
23
|
`;
|
|
24
24
|
}
|
|
25
25
|
console.log("\n🔍 Verificando registros después de la actualización...");
|
|
26
|
-
const remainingNullUuids = await prisma.$queryRaw `
|
|
27
|
-
SELECT COUNT(*) as count
|
|
28
|
-
FROM transactions
|
|
29
|
-
WHERE uuid IS NULL;
|
|
26
|
+
const remainingNullUuids = await prisma.$queryRaw `
|
|
27
|
+
SELECT COUNT(*) as count
|
|
28
|
+
FROM transactions
|
|
29
|
+
WHERE uuid IS NULL;
|
|
30
30
|
`;
|
|
31
31
|
if (remainingNullUuids[0].count > 0) {
|
|
32
32
|
throw new Error(`Aún hay ${remainingNullUuids[0].count} registros sin UUID después de la actualización`);
|
|
33
33
|
}
|
|
34
34
|
console.log("\n📝 Haciendo UUID requerido y añadiendo valor por defecto...");
|
|
35
|
-
await prisma.$executeRaw `
|
|
36
|
-
ALTER TABLE transactions
|
|
37
|
-
ALTER COLUMN uuid SET NOT NULL;
|
|
35
|
+
await prisma.$executeRaw `
|
|
36
|
+
ALTER TABLE transactions
|
|
37
|
+
ALTER COLUMN uuid SET NOT NULL;
|
|
38
38
|
`;
|
|
39
|
-
await prisma.$executeRaw `
|
|
40
|
-
ALTER TABLE transactions
|
|
41
|
-
ALTER COLUMN uuid
|
|
42
|
-
SET DEFAULT uuid_generate_v4();
|
|
39
|
+
await prisma.$executeRaw `
|
|
40
|
+
ALTER TABLE transactions
|
|
41
|
+
ALTER COLUMN uuid
|
|
42
|
+
SET DEFAULT uuid_generate_v4();
|
|
43
43
|
`;
|
|
44
44
|
console.log("\n✅ Migración completada exitosamente");
|
|
45
45
|
}
|
|
@@ -45,9 +45,9 @@ class PostMigrationValidator {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
this.logger.log("Starting post-migration validation");
|
|
48
|
-
const apiKeysResult = await this.sourcePool.query(`
|
|
49
|
-
SELECT api_key, provider_id
|
|
50
|
-
FROM api_keys
|
|
48
|
+
const apiKeysResult = await this.sourcePool.query(`
|
|
49
|
+
SELECT api_key, provider_id
|
|
50
|
+
FROM api_keys
|
|
51
51
|
`);
|
|
52
52
|
this.logger.log(`Found ${apiKeysResult.rows.length} API keys to validate`);
|
|
53
53
|
for (const apiKey of apiKeysResult.rows) {
|
|
@@ -101,11 +101,11 @@ class PostMigrationValidator {
|
|
|
101
101
|
async validateTenantData(tenantId, providerId) {
|
|
102
102
|
this.logger.log(`Validating data for tenant: ${tenantId} (Provider ID: ${providerId})`);
|
|
103
103
|
try {
|
|
104
|
-
const schemaExistsResult = await this.targetPool.query(`
|
|
105
|
-
SELECT 1
|
|
106
|
-
FROM information_schema.schemata
|
|
107
|
-
WHERE schema_name = $1
|
|
108
|
-
LIMIT 1
|
|
104
|
+
const schemaExistsResult = await this.targetPool.query(`
|
|
105
|
+
SELECT 1
|
|
106
|
+
FROM information_schema.schemata
|
|
107
|
+
WHERE schema_name = $1
|
|
108
|
+
LIMIT 1
|
|
109
109
|
`, [tenantId]);
|
|
110
110
|
if (schemaExistsResult.rows.length === 0) {
|
|
111
111
|
this.logger.warn(`Schema ${tenantId} does not exist in target database`);
|
|
@@ -117,12 +117,12 @@ class PostMigrationValidator {
|
|
|
117
117
|
});
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
-
const tablesResult = await this.sourcePool.query(`
|
|
121
|
-
SELECT table_name
|
|
122
|
-
FROM information_schema.tables
|
|
123
|
-
WHERE table_schema = 'public'
|
|
124
|
-
AND table_type = 'BASE TABLE'
|
|
125
|
-
AND table_name NOT IN ('_prisma_migrations', 'api_keys')
|
|
120
|
+
const tablesResult = await this.sourcePool.query(`
|
|
121
|
+
SELECT table_name
|
|
122
|
+
FROM information_schema.tables
|
|
123
|
+
WHERE table_schema = 'public'
|
|
124
|
+
AND table_type = 'BASE TABLE'
|
|
125
|
+
AND table_name NOT IN ('_prisma_migrations', 'api_keys')
|
|
126
126
|
`);
|
|
127
127
|
for (const tableRow of tablesResult.rows) {
|
|
128
128
|
const tableName = tableRow.table_name;
|
|
@@ -142,13 +142,13 @@ class PostMigrationValidator {
|
|
|
142
142
|
async validateTableData(tenantId, tableName, providerId) {
|
|
143
143
|
try {
|
|
144
144
|
let sourceCountQuery = `SELECT COUNT(*) as count FROM ${tableName}`;
|
|
145
|
-
const hasProviderIdResult = await this.sourcePool.query(`
|
|
146
|
-
SELECT 1
|
|
147
|
-
FROM information_schema.columns
|
|
148
|
-
WHERE table_schema = 'public'
|
|
149
|
-
AND table_name = $1
|
|
150
|
-
AND column_name = 'provider_id'
|
|
151
|
-
LIMIT 1
|
|
145
|
+
const hasProviderIdResult = await this.sourcePool.query(`
|
|
146
|
+
SELECT 1
|
|
147
|
+
FROM information_schema.columns
|
|
148
|
+
WHERE table_schema = 'public'
|
|
149
|
+
AND table_name = $1
|
|
150
|
+
AND column_name = 'provider_id'
|
|
151
|
+
LIMIT 1
|
|
152
152
|
`, [tableName]);
|
|
153
153
|
if (hasProviderIdResult.rows.length > 0) {
|
|
154
154
|
sourceCountQuery += ` WHERE provider_id = ${providerId}`;
|
|
@@ -197,49 +197,49 @@ class PostMigrationValidator {
|
|
|
197
197
|
}
|
|
198
198
|
async validateRandomRecords(tenantId, tableName, providerId) {
|
|
199
199
|
try {
|
|
200
|
-
const primaryKeyResult = await this.sourcePool.query(`
|
|
201
|
-
SELECT kcu.column_name
|
|
202
|
-
FROM information_schema.table_constraints tc
|
|
203
|
-
JOIN information_schema.key_column_usage kcu
|
|
204
|
-
ON tc.constraint_name = kcu.constraint_name
|
|
205
|
-
AND tc.table_schema = kcu.table_schema
|
|
206
|
-
WHERE tc.constraint_type = 'PRIMARY KEY'
|
|
207
|
-
AND tc.table_schema = 'public'
|
|
208
|
-
AND tc.table_name = $1
|
|
209
|
-
LIMIT 1
|
|
200
|
+
const primaryKeyResult = await this.sourcePool.query(`
|
|
201
|
+
SELECT kcu.column_name
|
|
202
|
+
FROM information_schema.table_constraints tc
|
|
203
|
+
JOIN information_schema.key_column_usage kcu
|
|
204
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
205
|
+
AND tc.table_schema = kcu.table_schema
|
|
206
|
+
WHERE tc.constraint_type = 'PRIMARY KEY'
|
|
207
|
+
AND tc.table_schema = 'public'
|
|
208
|
+
AND tc.table_name = $1
|
|
209
|
+
LIMIT 1
|
|
210
210
|
`, [tableName]);
|
|
211
211
|
if (primaryKeyResult.rows.length === 0) {
|
|
212
212
|
this.logger.warn(`No primary key found for table ${tableName}`);
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
215
|
const primaryKeyColumn = primaryKeyResult.rows[0].column_name;
|
|
216
|
-
let randomRecordsQuery = `
|
|
217
|
-
SELECT *
|
|
218
|
-
FROM ${tableName}
|
|
216
|
+
let randomRecordsQuery = `
|
|
217
|
+
SELECT *
|
|
218
|
+
FROM ${tableName}
|
|
219
219
|
`;
|
|
220
|
-
const hasProviderIdResult = await this.sourcePool.query(`
|
|
221
|
-
SELECT 1
|
|
222
|
-
FROM information_schema.columns
|
|
223
|
-
WHERE table_schema = 'public'
|
|
224
|
-
AND table_name = $1
|
|
225
|
-
AND column_name = 'provider_id'
|
|
226
|
-
LIMIT 1
|
|
220
|
+
const hasProviderIdResult = await this.sourcePool.query(`
|
|
221
|
+
SELECT 1
|
|
222
|
+
FROM information_schema.columns
|
|
223
|
+
WHERE table_schema = 'public'
|
|
224
|
+
AND table_name = $1
|
|
225
|
+
AND column_name = 'provider_id'
|
|
226
|
+
LIMIT 1
|
|
227
227
|
`, [tableName]);
|
|
228
228
|
if (hasProviderIdResult.rows.length > 0) {
|
|
229
229
|
randomRecordsQuery += ` WHERE provider_id = ${providerId}`;
|
|
230
230
|
}
|
|
231
|
-
randomRecordsQuery += `
|
|
232
|
-
ORDER BY RANDOM()
|
|
233
|
-
LIMIT 5
|
|
231
|
+
randomRecordsQuery += `
|
|
232
|
+
ORDER BY RANDOM()
|
|
233
|
+
LIMIT 5
|
|
234
234
|
`;
|
|
235
235
|
const randomRecordsResult = await this.sourcePool.query(randomRecordsQuery);
|
|
236
236
|
for (const sourceRecord of randomRecordsResult.rows) {
|
|
237
237
|
const primaryKeyValue = sourceRecord[primaryKeyColumn];
|
|
238
|
-
const targetRecordResult = await this.targetPool.query(`
|
|
239
|
-
SELECT *
|
|
240
|
-
FROM "${tenantId}"."${tableName}"
|
|
241
|
-
WHERE "${primaryKeyColumn}" = $1
|
|
242
|
-
LIMIT 1
|
|
238
|
+
const targetRecordResult = await this.targetPool.query(`
|
|
239
|
+
SELECT *
|
|
240
|
+
FROM "${tenantId}"."${tableName}"
|
|
241
|
+
WHERE "${primaryKeyColumn}" = $1
|
|
242
|
+
LIMIT 1
|
|
243
243
|
`, [primaryKeyValue]);
|
|
244
244
|
if (targetRecordResult.rows.length === 0) {
|
|
245
245
|
this.issues.push({
|