@javalabs/prisma-client 1.0.0
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/README.md +220 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/prisma-factory.service.d.ts +9 -0
- package/dist/prisma-factory.service.js +47 -0
- package/dist/prisma-factory.service.js.map +1 -0
- package/dist/prisma.module.d.ts +2 -0
- package/dist/prisma.module.js +23 -0
- package/dist/prisma.module.js.map +1 -0
- package/dist/prisma.service.d.ts +6 -0
- package/dist/prisma.service.js +27 -0
- package/dist/prisma.service.js.map +1 -0
- package/dist/scripts/create-tenant-schemas.d.ts +1 -0
- package/dist/scripts/create-tenant-schemas.js +117 -0
- package/dist/scripts/create-tenant-schemas.js.map +1 -0
- package/dist/scripts/data-migration/batch-migrator.d.ts +25 -0
- package/dist/scripts/data-migration/batch-migrator.js +333 -0
- package/dist/scripts/data-migration/batch-migrator.js.map +1 -0
- package/dist/scripts/data-migration/data-transformer.d.ts +17 -0
- package/dist/scripts/data-migration/data-transformer.js +242 -0
- package/dist/scripts/data-migration/data-transformer.js.map +1 -0
- package/dist/scripts/data-migration/db-connector.d.ts +7 -0
- package/dist/scripts/data-migration/db-connector.js +58 -0
- package/dist/scripts/data-migration/db-connector.js.map +1 -0
- package/dist/scripts/data-migration/dependency-manager.d.ts +9 -0
- package/dist/scripts/data-migration/dependency-manager.js +86 -0
- package/dist/scripts/data-migration/dependency-manager.js.map +1 -0
- package/dist/scripts/data-migration/dependency-resolver.d.ts +18 -0
- package/dist/scripts/data-migration/dependency-resolver.js +251 -0
- package/dist/scripts/data-migration/dependency-resolver.js.map +1 -0
- package/dist/scripts/data-migration/entity-discovery.d.ts +11 -0
- package/dist/scripts/data-migration/entity-discovery.js +152 -0
- package/dist/scripts/data-migration/entity-discovery.js.map +1 -0
- package/dist/scripts/data-migration/foreign-key-manager.d.ts +17 -0
- package/dist/scripts/data-migration/foreign-key-manager.js +70 -0
- package/dist/scripts/data-migration/foreign-key-manager.js.map +1 -0
- package/dist/scripts/data-migration/migration-phases.d.ts +5 -0
- package/dist/scripts/data-migration/migration-phases.js +55 -0
- package/dist/scripts/data-migration/migration-phases.js.map +1 -0
- package/dist/scripts/data-migration/migration-tool.d.ts +29 -0
- package/dist/scripts/data-migration/migration-tool.js +250 -0
- package/dist/scripts/data-migration/migration-tool.js.map +1 -0
- package/dist/scripts/data-migration/phase-generator.d.ts +15 -0
- package/dist/scripts/data-migration/phase-generator.js +187 -0
- package/dist/scripts/data-migration/phase-generator.js.map +1 -0
- package/dist/scripts/data-migration/schema-utils.d.ts +18 -0
- package/dist/scripts/data-migration/schema-utils.js +164 -0
- package/dist/scripts/data-migration/schema-utils.js.map +1 -0
- package/dist/scripts/data-migration/tenant-migrator.d.ts +15 -0
- package/dist/scripts/data-migration/tenant-migrator.js +110 -0
- package/dist/scripts/data-migration/tenant-migrator.js.map +1 -0
- package/dist/scripts/data-migration/typecast-manager.d.ts +5 -0
- package/dist/scripts/data-migration/typecast-manager.js +35 -0
- package/dist/scripts/data-migration/typecast-manager.js.map +1 -0
- package/dist/scripts/data-migration/types.d.ts +34 -0
- package/dist/scripts/data-migration/types.js +3 -0
- package/dist/scripts/data-migration/types.js.map +1 -0
- package/dist/scripts/data-migration.d.ts +22 -0
- package/dist/scripts/data-migration.js +593 -0
- package/dist/scripts/data-migration.js.map +1 -0
- package/dist/scripts/drop-database.d.ts +10 -0
- package/dist/scripts/drop-database.js +81 -0
- package/dist/scripts/drop-database.js.map +1 -0
- package/dist/scripts/error-handler.d.ts +12 -0
- package/dist/scripts/error-handler.js +82 -0
- package/dist/scripts/error-handler.js.map +1 -0
- package/dist/scripts/fix-data-types.d.ts +10 -0
- package/dist/scripts/fix-data-types.js +185 -0
- package/dist/scripts/fix-data-types.js.map +1 -0
- package/dist/scripts/fix-enum-values.d.ts +17 -0
- package/dist/scripts/fix-enum-values.js +234 -0
- package/dist/scripts/fix-enum-values.js.map +1 -0
- package/dist/scripts/fix-schema-discrepancies.d.ts +21 -0
- package/dist/scripts/fix-schema-discrepancies.js +240 -0
- package/dist/scripts/fix-schema-discrepancies.js.map +1 -0
- package/dist/scripts/migrate-schema-structure.d.ts +1 -0
- package/dist/scripts/migrate-schema-structure.js +76 -0
- package/dist/scripts/migrate-schema-structure.js.map +1 -0
- package/dist/scripts/post-migration-validator.d.ts +21 -0
- package/dist/scripts/post-migration-validator.js +341 -0
- package/dist/scripts/post-migration-validator.js.map +1 -0
- package/dist/scripts/pre-migration-validator.d.ts +25 -0
- package/dist/scripts/pre-migration-validator.js +491 -0
- package/dist/scripts/pre-migration-validator.js.map +1 -0
- package/dist/scripts/reset-database.d.ts +17 -0
- package/dist/scripts/reset-database.js +202 -0
- package/dist/scripts/reset-database.js.map +1 -0
- package/dist/scripts/retry-failed-migrations.d.ts +14 -0
- package/dist/scripts/retry-failed-migrations.js +301 -0
- package/dist/scripts/retry-failed-migrations.js.map +1 -0
- package/dist/scripts/run-migration.d.ts +1 -0
- package/dist/scripts/run-migration.js +525 -0
- package/dist/scripts/run-migration.js.map +1 -0
- package/dist/scripts/schema-sync.d.ts +1 -0
- package/dist/scripts/schema-sync.js +85 -0
- package/dist/scripts/schema-sync.js.map +1 -0
- package/dist/scripts/sync-enum-types.d.ts +13 -0
- package/dist/scripts/sync-enum-types.js +139 -0
- package/dist/scripts/sync-enum-types.js.map +1 -0
- package/dist/scripts/sync-enum-values.d.ts +20 -0
- package/dist/scripts/sync-enum-values.js +336 -0
- package/dist/scripts/sync-enum-values.js.map +1 -0
- package/dist/scripts/truncate-database.d.ts +10 -0
- package/dist/scripts/truncate-database.js +100 -0
- package/dist/scripts/truncate-database.js.map +1 -0
- package/dist/scripts/verify-migration-setup.d.ts +11 -0
- package/dist/scripts/verify-migration-setup.js +120 -0
- package/dist/scripts/verify-migration-setup.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/migration-config-public.json +95 -0
- package/migration-config.json +95 -0
- package/package.json +33 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +360 -0
- package/src/index.ts +23 -0
- package/src/prisma-factory.service.ts +41 -0
- package/src/prisma.module.ts +10 -0
- package/src/prisma.service.ts +17 -0
- package/src/scripts/create-tenant-schemas.ts +146 -0
- package/src/scripts/data-migration/batch-migrator.ts +569 -0
- package/src/scripts/data-migration/data-transformer.ts +377 -0
- package/src/scripts/data-migration/db-connector.ts +67 -0
- package/src/scripts/data-migration/dependency-resolver.ts +319 -0
- package/src/scripts/data-migration/entity-discovery.ts +197 -0
- package/src/scripts/data-migration/foreign-key-manager.ts +95 -0
- package/src/scripts/data-migration/migration-tool.ts +357 -0
- package/src/scripts/data-migration/schema-utils.ts +186 -0
- package/src/scripts/data-migration/tenant-migrator.ts +194 -0
- package/src/scripts/data-migration/typecast-manager.ts +38 -0
- package/src/scripts/data-migration/types.ts +40 -0
- package/src/scripts/drop-database.ts +105 -0
- package/src/scripts/dump-source-db.sh +62 -0
- package/src/scripts/dumps/source_dump_20250413_112626.sql +1527 -0
- package/src/scripts/error-handler.ts +118 -0
- package/src/scripts/fix-data-types.ts +242 -0
- package/src/scripts/fix-enum-values.ts +357 -0
- package/src/scripts/fix-schema-discrepancies.ts +318 -0
- package/src/scripts/migrate-schema-structure.ts +90 -0
- package/src/scripts/post-migration-validator.ts +427 -0
- package/src/scripts/pre-migration-validator.ts +611 -0
- package/src/scripts/reset-database.ts +264 -0
- package/src/scripts/retry-failed-migrations.ts +416 -0
- package/src/scripts/run-migration.ts +691 -0
- package/src/scripts/schema-sync.ts +129 -0
- package/src/scripts/sync-enum-types.ts +171 -0
- package/src/scripts/sync-enum-values.ts +563 -0
- package/src/scripts/truncate-database.ts +124 -0
- package/src/scripts/verify-migration-setup.ts +136 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as dotenv from 'dotenv';
|
|
2
|
+
import * as pg from 'pg';
|
|
3
|
+
import { Logger } from '@nestjs/common';
|
|
4
|
+
|
|
5
|
+
dotenv.config();
|
|
6
|
+
|
|
7
|
+
export class MigrationSetupVerifier {
|
|
8
|
+
private readonly logger = new Logger('MigrationSetupVerifier');
|
|
9
|
+
private readonly sourcePool: pg.Pool;
|
|
10
|
+
private readonly targetPool: pg.Pool;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
this.sourcePool = new pg.Pool({
|
|
14
|
+
connectionString: process.env.SOURCE_DATABASE_URL,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
this.targetPool = new pg.Pool({
|
|
18
|
+
connectionString: process.env.DATABASE_URL,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async verifySetup() {
|
|
23
|
+
this.logger.log('Starting migration setup verification');
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
// Verificar conexiones
|
|
27
|
+
await this.verifyConnections();
|
|
28
|
+
|
|
29
|
+
// Verificar tenants
|
|
30
|
+
await this.verifyTenants();
|
|
31
|
+
|
|
32
|
+
// Verificar esquemas
|
|
33
|
+
await this.verifySchemas();
|
|
34
|
+
|
|
35
|
+
this.logger.log('Migration setup verification completed');
|
|
36
|
+
} catch (error) {
|
|
37
|
+
this.logger.error(`Error during setup verification: ${error.message}`);
|
|
38
|
+
} finally {
|
|
39
|
+
await this.cleanup();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private async verifyConnections() {
|
|
44
|
+
this.logger.log('Verifying database connections...');
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const sourceClient = await this.sourcePool.connect();
|
|
48
|
+
const sourceResult = await sourceClient.query('SELECT NOW() as time');
|
|
49
|
+
sourceClient.release();
|
|
50
|
+
this.logger.log(`Source database connection successful: ${sourceResult.rows[0].time}`);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
this.logger.error(`Source database connection failed: ${error.message}`);
|
|
53
|
+
throw new Error('Source database connection failed');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const targetClient = await this.targetPool.connect();
|
|
58
|
+
const targetResult = await targetClient.query('SELECT NOW() as time');
|
|
59
|
+
targetClient.release();
|
|
60
|
+
this.logger.log(`Target database connection successful: ${targetResult.rows[0].time}`);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
this.logger.error(`Target database connection failed: ${error.message}`);
|
|
63
|
+
throw new Error('Target database connection failed');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private async verifyTenants() {
|
|
68
|
+
this.logger.log('Verifying tenants in source database...');
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const result = await this.sourcePool.query(`
|
|
72
|
+
SELECT api_key, provider_id
|
|
73
|
+
FROM api_keys
|
|
74
|
+
WHERE api_key != ''
|
|
75
|
+
AND provider_id IS NOT NULL
|
|
76
|
+
`);
|
|
77
|
+
|
|
78
|
+
this.logger.log(`Found ${result.rows.length} valid tenants in source database`);
|
|
79
|
+
|
|
80
|
+
if (result.rows.length === 0) {
|
|
81
|
+
this.logger.warn('No valid tenants found in source database!');
|
|
82
|
+
this.logger.log('Will use "public" schema as default source for migration');
|
|
83
|
+
} else {
|
|
84
|
+
// Mostrar algunos ejemplos
|
|
85
|
+
const examples = result.rows.slice(0, 5);
|
|
86
|
+
this.logger.log(`Sample tenants: ${JSON.stringify(examples)}`);
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
this.logger.error(`Error verifying tenants: ${error.message}`);
|
|
90
|
+
this.logger.log('Will use "public" schema as default source for migration');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private async verifySchemas() {
|
|
95
|
+
this.logger.log('Verifying schemas in target database...');
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const result = await this.targetPool.query(`
|
|
99
|
+
SELECT schema_name
|
|
100
|
+
FROM information_schema.schemata
|
|
101
|
+
WHERE schema_name NOT IN ('public', 'information_schema', 'pg_catalog', 'pg_toast')
|
|
102
|
+
AND schema_name NOT LIKE 'pg_%'
|
|
103
|
+
`);
|
|
104
|
+
|
|
105
|
+
this.logger.log(`Found ${result.rows.length} schemas in target database`);
|
|
106
|
+
|
|
107
|
+
if (result.rows.length === 0) {
|
|
108
|
+
this.logger.warn('No tenant schemas found in target database!');
|
|
109
|
+
} else {
|
|
110
|
+
// Mostrar algunos ejemplos
|
|
111
|
+
const examples = result.rows.slice(0, 5);
|
|
112
|
+
this.logger.log(`Sample schemas: ${JSON.stringify(examples)}`);
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
this.logger.error(`Error verifying schemas: ${error.message}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private async cleanup() {
|
|
120
|
+
try {
|
|
121
|
+
await this.sourcePool.end();
|
|
122
|
+
await this.targetPool.end();
|
|
123
|
+
} catch (error) {
|
|
124
|
+
this.logger.error(`Error during cleanup: ${error.message}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Ejecutar la verificación si este archivo se ejecuta directamente
|
|
130
|
+
if (require.main === module) {
|
|
131
|
+
const verifier = new MigrationSetupVerifier();
|
|
132
|
+
verifier.verifySetup().catch(error => {
|
|
133
|
+
console.error('Verification failed:', error);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
});
|
|
136
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"target": "es2017",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"skipLibCheck": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*"],
|
|
17
|
+
"exclude": ["node_modules", "dist"]
|
|
18
|
+
}
|