@javalabs/prisma-client 1.0.16 → 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 +56 -4
- 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
|
@@ -103,8 +103,8 @@ class PreMigrationValidator {
|
|
|
103
103
|
async validateApiKeys() {
|
|
104
104
|
this.logger.log('Validating API keys');
|
|
105
105
|
try {
|
|
106
|
-
const result = await this.sourcePool.query(`
|
|
107
|
-
SELECT COUNT(*) as count FROM api_keys
|
|
106
|
+
const result = await this.sourcePool.query(`
|
|
107
|
+
SELECT COUNT(*) as count FROM api_keys
|
|
108
108
|
`);
|
|
109
109
|
const count = parseInt(result.rows[0].count);
|
|
110
110
|
if (count === 0) {
|
|
@@ -129,35 +129,35 @@ class PreMigrationValidator {
|
|
|
129
129
|
async validateDataTypeCompatibility() {
|
|
130
130
|
this.logger.log('Validating data type compatibility');
|
|
131
131
|
try {
|
|
132
|
-
const tablesResult = await this.sourcePool.query(`
|
|
133
|
-
SELECT table_name
|
|
134
|
-
FROM information_schema.tables
|
|
135
|
-
WHERE table_schema = 'public'
|
|
136
|
-
AND table_type = 'BASE TABLE'
|
|
132
|
+
const tablesResult = await this.sourcePool.query(`
|
|
133
|
+
SELECT table_name
|
|
134
|
+
FROM information_schema.tables
|
|
135
|
+
WHERE table_schema = 'public'
|
|
136
|
+
AND table_type = 'BASE TABLE'
|
|
137
137
|
`);
|
|
138
138
|
for (const tableRow of tablesResult.rows) {
|
|
139
139
|
const tableName = tableRow.table_name;
|
|
140
|
-
const sourceColumnsResult = await this.sourcePool.query(`
|
|
141
|
-
SELECT column_name, data_type, udt_name
|
|
142
|
-
FROM information_schema.columns
|
|
143
|
-
WHERE table_schema = 'public'
|
|
144
|
-
AND table_name = $1
|
|
140
|
+
const sourceColumnsResult = await this.sourcePool.query(`
|
|
141
|
+
SELECT column_name, data_type, udt_name
|
|
142
|
+
FROM information_schema.columns
|
|
143
|
+
WHERE table_schema = 'public'
|
|
144
|
+
AND table_name = $1
|
|
145
145
|
`, [tableName]);
|
|
146
|
-
const targetTableExists = await this.targetPool.query(`
|
|
147
|
-
SELECT 1
|
|
148
|
-
FROM information_schema.tables
|
|
149
|
-
WHERE table_schema = 'public'
|
|
150
|
-
AND table_name = $1
|
|
151
|
-
LIMIT 1
|
|
146
|
+
const targetTableExists = await this.targetPool.query(`
|
|
147
|
+
SELECT 1
|
|
148
|
+
FROM information_schema.tables
|
|
149
|
+
WHERE table_schema = 'public'
|
|
150
|
+
AND table_name = $1
|
|
151
|
+
LIMIT 1
|
|
152
152
|
`, [tableName]);
|
|
153
153
|
if (targetTableExists.rows.length === 0) {
|
|
154
154
|
continue;
|
|
155
155
|
}
|
|
156
|
-
const targetColumnsResult = await this.targetPool.query(`
|
|
157
|
-
SELECT column_name, data_type, udt_name
|
|
158
|
-
FROM information_schema.columns
|
|
159
|
-
WHERE table_schema = 'public'
|
|
160
|
-
AND table_name = $1
|
|
156
|
+
const targetColumnsResult = await this.targetPool.query(`
|
|
157
|
+
SELECT column_name, data_type, udt_name
|
|
158
|
+
FROM information_schema.columns
|
|
159
|
+
WHERE table_schema = 'public'
|
|
160
|
+
AND table_name = $1
|
|
161
161
|
`, [tableName]);
|
|
162
162
|
const sourceColumns = sourceColumnsResult.rows.reduce((map, col) => {
|
|
163
163
|
map[col.column_name] = col;
|
|
@@ -217,28 +217,28 @@ class PreMigrationValidator {
|
|
|
217
217
|
async validateColumnSizes() {
|
|
218
218
|
this.logger.log('Validating column sizes');
|
|
219
219
|
try {
|
|
220
|
-
const tablesResult = await this.sourcePool.query(`
|
|
221
|
-
SELECT table_name
|
|
222
|
-
FROM information_schema.tables
|
|
223
|
-
WHERE table_schema = 'public'
|
|
224
|
-
AND table_type = 'BASE TABLE'
|
|
220
|
+
const tablesResult = await this.sourcePool.query(`
|
|
221
|
+
SELECT table_name
|
|
222
|
+
FROM information_schema.tables
|
|
223
|
+
WHERE table_schema = 'public'
|
|
224
|
+
AND table_type = 'BASE TABLE'
|
|
225
225
|
`);
|
|
226
226
|
for (const tableRow of tablesResult.rows) {
|
|
227
227
|
const tableName = tableRow.table_name;
|
|
228
|
-
const sourceColumnsResult = await this.sourcePool.query(`
|
|
229
|
-
SELECT column_name, data_type, character_maximum_length
|
|
230
|
-
FROM information_schema.columns
|
|
231
|
-
WHERE table_schema = 'public'
|
|
232
|
-
AND table_name = $1
|
|
233
|
-
AND data_type IN ('character varying', 'character', 'varchar', 'char')
|
|
234
|
-
AND character_maximum_length IS NOT NULL
|
|
228
|
+
const sourceColumnsResult = await this.sourcePool.query(`
|
|
229
|
+
SELECT column_name, data_type, character_maximum_length
|
|
230
|
+
FROM information_schema.columns
|
|
231
|
+
WHERE table_schema = 'public'
|
|
232
|
+
AND table_name = $1
|
|
233
|
+
AND data_type IN ('character varying', 'character', 'varchar', 'char')
|
|
234
|
+
AND character_maximum_length IS NOT NULL
|
|
235
235
|
`, [tableName]);
|
|
236
|
-
const targetTableExists = await this.targetPool.query(`
|
|
237
|
-
SELECT 1
|
|
238
|
-
FROM information_schema.tables
|
|
239
|
-
WHERE table_schema = 'public'
|
|
240
|
-
AND table_name = $1
|
|
241
|
-
LIMIT 1
|
|
236
|
+
const targetTableExists = await this.targetPool.query(`
|
|
237
|
+
SELECT 1
|
|
238
|
+
FROM information_schema.tables
|
|
239
|
+
WHERE table_schema = 'public'
|
|
240
|
+
AND table_name = $1
|
|
241
|
+
LIMIT 1
|
|
242
242
|
`, [tableName]);
|
|
243
243
|
if (targetTableExists.rows.length === 0) {
|
|
244
244
|
continue;
|
|
@@ -246,13 +246,13 @@ class PreMigrationValidator {
|
|
|
246
246
|
for (const sourceColumn of sourceColumnsResult.rows) {
|
|
247
247
|
const columnName = sourceColumn.column_name;
|
|
248
248
|
const sourceMaxLength = sourceColumn.character_maximum_length;
|
|
249
|
-
const targetColumnResult = await this.targetPool.query(`
|
|
250
|
-
SELECT character_maximum_length
|
|
251
|
-
FROM information_schema.columns
|
|
252
|
-
WHERE table_schema = 'public'
|
|
253
|
-
AND table_name = $1
|
|
254
|
-
AND column_name = $2
|
|
255
|
-
AND data_type IN ('character varying', 'character', 'varchar', 'char')
|
|
249
|
+
const targetColumnResult = await this.targetPool.query(`
|
|
250
|
+
SELECT character_maximum_length
|
|
251
|
+
FROM information_schema.columns
|
|
252
|
+
WHERE table_schema = 'public'
|
|
253
|
+
AND table_name = $1
|
|
254
|
+
AND column_name = $2
|
|
255
|
+
AND data_type IN ('character varying', 'character', 'varchar', 'char')
|
|
256
256
|
`, [tableName, columnName]);
|
|
257
257
|
if (targetColumnResult.rows.length > 0) {
|
|
258
258
|
const targetMaxLength = targetColumnResult.rows[0].character_maximum_length;
|
|
@@ -282,41 +282,41 @@ class PreMigrationValidator {
|
|
|
282
282
|
async validateEnumValues() {
|
|
283
283
|
this.logger.log('Validating enum values');
|
|
284
284
|
try {
|
|
285
|
-
const sourceEnumsResult = await this.sourcePool.query(`
|
|
286
|
-
SELECT t.typname AS enum_name
|
|
287
|
-
FROM pg_type t
|
|
288
|
-
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
|
289
|
-
WHERE t.typtype = 'e'
|
|
290
|
-
AND n.nspname = 'public'
|
|
285
|
+
const sourceEnumsResult = await this.sourcePool.query(`
|
|
286
|
+
SELECT t.typname AS enum_name
|
|
287
|
+
FROM pg_type t
|
|
288
|
+
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
|
289
|
+
WHERE t.typtype = 'e'
|
|
290
|
+
AND n.nspname = 'public'
|
|
291
291
|
`);
|
|
292
292
|
for (const enumRow of sourceEnumsResult.rows) {
|
|
293
293
|
const enumName = enumRow.enum_name;
|
|
294
|
-
const sourceEnumValuesResult = await this.sourcePool.query(`
|
|
295
|
-
SELECT e.enumlabel
|
|
296
|
-
FROM pg_enum e
|
|
297
|
-
JOIN pg_type t ON e.enumtypid = t.oid
|
|
298
|
-
WHERE t.typname = $1
|
|
299
|
-
ORDER BY e.enumsortorder
|
|
294
|
+
const sourceEnumValuesResult = await this.sourcePool.query(`
|
|
295
|
+
SELECT e.enumlabel
|
|
296
|
+
FROM pg_enum e
|
|
297
|
+
JOIN pg_type t ON e.enumtypid = t.oid
|
|
298
|
+
WHERE t.typname = $1
|
|
299
|
+
ORDER BY e.enumsortorder
|
|
300
300
|
`, [enumName]);
|
|
301
301
|
const sourceEnumValues = sourceEnumValuesResult.rows.map(row => row.enumlabel);
|
|
302
|
-
const targetEnumExistsResult = await this.targetPool.query(`
|
|
303
|
-
SELECT 1
|
|
304
|
-
FROM pg_type t
|
|
305
|
-
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
|
306
|
-
WHERE t.typtype = 'e'
|
|
307
|
-
AND t.typname = $1
|
|
308
|
-
AND n.nspname = 'public'
|
|
309
|
-
LIMIT 1
|
|
302
|
+
const targetEnumExistsResult = await this.targetPool.query(`
|
|
303
|
+
SELECT 1
|
|
304
|
+
FROM pg_type t
|
|
305
|
+
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
|
306
|
+
WHERE t.typtype = 'e'
|
|
307
|
+
AND t.typname = $1
|
|
308
|
+
AND n.nspname = 'public'
|
|
309
|
+
LIMIT 1
|
|
310
310
|
`, [enumName]);
|
|
311
311
|
if (targetEnumExistsResult.rows.length === 0) {
|
|
312
312
|
continue;
|
|
313
313
|
}
|
|
314
|
-
const targetEnumValuesResult = await this.targetPool.query(`
|
|
315
|
-
SELECT e.enumlabel
|
|
316
|
-
FROM pg_enum e
|
|
317
|
-
JOIN pg_type t ON e.enumtypid = t.oid
|
|
318
|
-
WHERE t.typname = $1
|
|
319
|
-
ORDER BY e.enumsortorder
|
|
314
|
+
const targetEnumValuesResult = await this.targetPool.query(`
|
|
315
|
+
SELECT e.enumlabel
|
|
316
|
+
FROM pg_enum e
|
|
317
|
+
JOIN pg_type t ON e.enumtypid = t.oid
|
|
318
|
+
WHERE t.typname = $1
|
|
319
|
+
ORDER BY e.enumsortorder
|
|
320
320
|
`, [enumName]);
|
|
321
321
|
const targetEnumValues = targetEnumValuesResult.rows.map(row => row.enumlabel);
|
|
322
322
|
for (const sourceValue of sourceEnumValues) {
|
|
@@ -343,22 +343,22 @@ class PreMigrationValidator {
|
|
|
343
343
|
async validateForeignKeyConstraints() {
|
|
344
344
|
this.logger.log('Validating foreign key constraints');
|
|
345
345
|
try {
|
|
346
|
-
const foreignKeysResult = await this.sourcePool.query(`
|
|
347
|
-
SELECT
|
|
348
|
-
tc.table_name,
|
|
349
|
-
kcu.column_name,
|
|
350
|
-
ccu.table_name AS foreign_table_name,
|
|
351
|
-
ccu.column_name AS foreign_column_name
|
|
352
|
-
FROM
|
|
353
|
-
information_schema.table_constraints AS tc
|
|
354
|
-
JOIN information_schema.key_column_usage AS kcu
|
|
355
|
-
ON tc.constraint_name = kcu.constraint_name
|
|
356
|
-
AND tc.table_schema = kcu.table_schema
|
|
357
|
-
JOIN information_schema.constraint_column_usage AS ccu
|
|
358
|
-
ON ccu.constraint_name = tc.constraint_name
|
|
359
|
-
AND ccu.table_schema = tc.table_schema
|
|
360
|
-
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
361
|
-
AND tc.table_schema = 'public'
|
|
346
|
+
const foreignKeysResult = await this.sourcePool.query(`
|
|
347
|
+
SELECT
|
|
348
|
+
tc.table_name,
|
|
349
|
+
kcu.column_name,
|
|
350
|
+
ccu.table_name AS foreign_table_name,
|
|
351
|
+
ccu.column_name AS foreign_column_name
|
|
352
|
+
FROM
|
|
353
|
+
information_schema.table_constraints AS tc
|
|
354
|
+
JOIN information_schema.key_column_usage AS kcu
|
|
355
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
356
|
+
AND tc.table_schema = kcu.table_schema
|
|
357
|
+
JOIN information_schema.constraint_column_usage AS ccu
|
|
358
|
+
ON ccu.constraint_name = tc.constraint_name
|
|
359
|
+
AND ccu.table_schema = tc.table_schema
|
|
360
|
+
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
361
|
+
AND tc.table_schema = 'public'
|
|
362
362
|
`);
|
|
363
363
|
this.logger.log(`Found ${foreignKeysResult.rows.length} foreign key constraints in source database`);
|
|
364
364
|
}
|
|
@@ -373,28 +373,28 @@ class PreMigrationValidator {
|
|
|
373
373
|
async validateUniqueConstraints() {
|
|
374
374
|
this.logger.log('Validating unique constraints...');
|
|
375
375
|
try {
|
|
376
|
-
const sourceConstraintsQuery = `
|
|
377
|
-
SELECT
|
|
378
|
-
tc.table_name,
|
|
379
|
-
kcu.column_name
|
|
380
|
-
FROM
|
|
381
|
-
information_schema.table_constraints tc
|
|
382
|
-
JOIN information_schema.key_column_usage kcu
|
|
383
|
-
ON tc.constraint_name = kcu.constraint_name
|
|
384
|
-
WHERE
|
|
385
|
-
tc.constraint_type = 'UNIQUE'
|
|
386
|
-
AND tc.table_schema = 'public'
|
|
376
|
+
const sourceConstraintsQuery = `
|
|
377
|
+
SELECT
|
|
378
|
+
tc.table_name,
|
|
379
|
+
kcu.column_name
|
|
380
|
+
FROM
|
|
381
|
+
information_schema.table_constraints tc
|
|
382
|
+
JOIN information_schema.key_column_usage kcu
|
|
383
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
384
|
+
WHERE
|
|
385
|
+
tc.constraint_type = 'UNIQUE'
|
|
386
|
+
AND tc.table_schema = 'public'
|
|
387
387
|
`;
|
|
388
388
|
const sourceConstraints = await this.sourcePool.query(sourceConstraintsQuery);
|
|
389
389
|
for (const constraint of sourceConstraints.rows) {
|
|
390
390
|
const { table_name, column_name } = constraint;
|
|
391
391
|
try {
|
|
392
|
-
const columnExistsQuery = `
|
|
393
|
-
SELECT column_name
|
|
394
|
-
FROM information_schema.columns
|
|
395
|
-
WHERE table_name = $1
|
|
396
|
-
AND column_name = $2
|
|
397
|
-
AND table_schema = 'public'
|
|
392
|
+
const columnExistsQuery = `
|
|
393
|
+
SELECT column_name
|
|
394
|
+
FROM information_schema.columns
|
|
395
|
+
WHERE table_name = $1
|
|
396
|
+
AND column_name = $2
|
|
397
|
+
AND table_schema = 'public'
|
|
398
398
|
`;
|
|
399
399
|
const columnExists = await this.targetPool.query(columnExistsQuery, [table_name, column_name]);
|
|
400
400
|
if (columnExists.rows.length === 0) {
|
|
@@ -105,12 +105,12 @@ class DatabaseResetTool {
|
|
|
105
105
|
async dropAllCustomTypes() {
|
|
106
106
|
this.logger.log("Dropping all custom types (enums, domains, etc.)");
|
|
107
107
|
try {
|
|
108
|
-
const typesQuery = `
|
|
109
|
-
SELECT t.typname AS name
|
|
110
|
-
FROM pg_type t
|
|
111
|
-
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
|
112
|
-
WHERE n.nspname = 'public'
|
|
113
|
-
AND t.typtype = 'e' -- enum types
|
|
108
|
+
const typesQuery = `
|
|
109
|
+
SELECT t.typname AS name
|
|
110
|
+
FROM pg_type t
|
|
111
|
+
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
|
112
|
+
WHERE n.nspname = 'public'
|
|
113
|
+
AND t.typtype = 'e' -- enum types
|
|
114
114
|
`;
|
|
115
115
|
const typesResult = await this.pool.query(typesQuery);
|
|
116
116
|
const types = typesResult.rows.map(row => row.name);
|
|
@@ -130,20 +130,20 @@ class DatabaseResetTool {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
async getCustomSchemas() {
|
|
133
|
-
const result = await this.pool.query(`
|
|
134
|
-
SELECT schema_name
|
|
135
|
-
FROM information_schema.schemata
|
|
136
|
-
WHERE schema_name NOT IN ('public', 'information_schema', 'pg_catalog', 'pg_toast')
|
|
137
|
-
AND schema_name NOT LIKE 'pg_%'
|
|
133
|
+
const result = await this.pool.query(`
|
|
134
|
+
SELECT schema_name
|
|
135
|
+
FROM information_schema.schemata
|
|
136
|
+
WHERE schema_name NOT IN ('public', 'information_schema', 'pg_catalog', 'pg_toast')
|
|
137
|
+
AND schema_name NOT LIKE 'pg_%'
|
|
138
138
|
`);
|
|
139
139
|
return result.rows.map(row => row.schema_name);
|
|
140
140
|
}
|
|
141
141
|
async getPublicTables() {
|
|
142
|
-
const result = await this.pool.query(`
|
|
143
|
-
SELECT table_name
|
|
144
|
-
FROM information_schema.tables
|
|
145
|
-
WHERE table_schema = 'public'
|
|
146
|
-
AND table_type = 'BASE TABLE'
|
|
142
|
+
const result = await this.pool.query(`
|
|
143
|
+
SELECT table_name
|
|
144
|
+
FROM information_schema.tables
|
|
145
|
+
WHERE table_schema = 'public'
|
|
146
|
+
AND table_type = 'BASE TABLE'
|
|
147
147
|
`);
|
|
148
148
|
return result.rows.map(row => row.table_name);
|
|
149
149
|
}
|
|
@@ -154,11 +154,11 @@ class DatabaseResetTool {
|
|
|
154
154
|
async terminateConnections(dbName) {
|
|
155
155
|
this.logger.log(`Terminating all connections to database: ${dbName}`);
|
|
156
156
|
try {
|
|
157
|
-
await this.adminPool.query(`
|
|
158
|
-
SELECT pg_terminate_backend(pg_stat_activity.pid)
|
|
159
|
-
FROM pg_stat_activity
|
|
160
|
-
WHERE pg_stat_activity.datname = $1
|
|
161
|
-
AND pid <> pg_backend_pid()
|
|
157
|
+
await this.adminPool.query(`
|
|
158
|
+
SELECT pg_terminate_backend(pg_stat_activity.pid)
|
|
159
|
+
FROM pg_stat_activity
|
|
160
|
+
WHERE pg_stat_activity.datname = $1
|
|
161
|
+
AND pid <> pg_backend_pid()
|
|
162
162
|
`, [dbName]);
|
|
163
163
|
this.logger.log("All connections terminated successfully");
|
|
164
164
|
}
|
|
@@ -131,10 +131,10 @@ class FailedMigrationRetry {
|
|
|
131
131
|
if (columnNames.includes(recordId)) {
|
|
132
132
|
createData[recordId] = data[recordId];
|
|
133
133
|
}
|
|
134
|
-
const checkExistQuery = `
|
|
135
|
-
SELECT 1 FROM "${tenantId}"."${entity}"
|
|
136
|
-
WHERE "${recordId}" = $1
|
|
137
|
-
LIMIT 1
|
|
134
|
+
const checkExistQuery = `
|
|
135
|
+
SELECT 1 FROM "${tenantId}"."${entity}"
|
|
136
|
+
WHERE "${recordId}" = $1
|
|
137
|
+
LIMIT 1
|
|
138
138
|
`;
|
|
139
139
|
const existResult = await this.targetPool.query(checkExistQuery, [
|
|
140
140
|
data[recordId],
|
|
@@ -150,10 +150,10 @@ class FailedMigrationRetry {
|
|
|
150
150
|
return `"${key}" = $${index + 2}`;
|
|
151
151
|
});
|
|
152
152
|
if (updateFields.length > 0) {
|
|
153
|
-
const updateQuery = `
|
|
154
|
-
UPDATE "${tenantId}"."${entity}"
|
|
155
|
-
SET ${updateFields.join(", ")}
|
|
156
|
-
WHERE "${recordId}" = $1
|
|
153
|
+
const updateQuery = `
|
|
154
|
+
UPDATE "${tenantId}"."${entity}"
|
|
155
|
+
SET ${updateFields.join(", ")}
|
|
156
|
+
WHERE "${recordId}" = $1
|
|
157
157
|
`;
|
|
158
158
|
const updateValues = [
|
|
159
159
|
data[recordId],
|
|
@@ -176,9 +176,9 @@ class FailedMigrationRetry {
|
|
|
176
176
|
}
|
|
177
177
|
return `$${index + 1}`;
|
|
178
178
|
});
|
|
179
|
-
const insertQuery = `
|
|
180
|
-
INSERT INTO "${tenantId}"."${entity}" (${insertFields.join(", ")})
|
|
181
|
-
VALUES (${insertPlaceholders.join(", ")})
|
|
179
|
+
const insertQuery = `
|
|
180
|
+
INSERT INTO "${tenantId}"."${entity}" (${insertFields.join(", ")})
|
|
181
|
+
VALUES (${insertPlaceholders.join(", ")})
|
|
182
182
|
`;
|
|
183
183
|
const insertValues = Object.keys(createData)
|
|
184
184
|
.filter(key => key !== '_enumTypes')
|
|
@@ -196,11 +196,11 @@ class FailedMigrationRetry {
|
|
|
196
196
|
}
|
|
197
197
|
await tenantPrisma.$disconnect();
|
|
198
198
|
}
|
|
199
|
-
this.logger.log(`
|
|
200
|
-
Retry Summary:
|
|
201
|
-
- Total errors: ${totalErrors}
|
|
202
|
-
- Successfully retried: ${retrySuccessCount}
|
|
203
|
-
- Failed retries: ${retryFailCount}
|
|
199
|
+
this.logger.log(`
|
|
200
|
+
Retry Summary:
|
|
201
|
+
- Total errors: ${totalErrors}
|
|
202
|
+
- Successfully retried: ${retrySuccessCount}
|
|
203
|
+
- Failed retries: ${retryFailCount}
|
|
204
204
|
`);
|
|
205
205
|
const remainingErrorsReport = this.errorHandler.generateErrorReport();
|
|
206
206
|
this.logger.log("Remaining Errors Report:\n" + remainingErrorsReport);
|
|
@@ -214,12 +214,12 @@ Retry Summary:
|
|
|
214
214
|
}
|
|
215
215
|
async getTableSchema(tableName, schemaName) {
|
|
216
216
|
try {
|
|
217
|
-
const schemaQuery = `
|
|
218
|
-
SELECT column_name, data_type, column_default, is_nullable, udt_name
|
|
219
|
-
FROM information_schema.columns
|
|
220
|
-
WHERE table_name = $1
|
|
221
|
-
AND table_schema = $2
|
|
222
|
-
ORDER BY ordinal_position
|
|
217
|
+
const schemaQuery = `
|
|
218
|
+
SELECT column_name, data_type, column_default, is_nullable, udt_name
|
|
219
|
+
FROM information_schema.columns
|
|
220
|
+
WHERE table_name = $1
|
|
221
|
+
AND table_schema = $2
|
|
222
|
+
ORDER BY ordinal_position
|
|
223
223
|
`;
|
|
224
224
|
const result = await this.targetPool.query(schemaQuery, [
|
|
225
225
|
tableName,
|
|
@@ -234,12 +234,12 @@ Retry Summary:
|
|
|
234
234
|
}
|
|
235
235
|
async getEnumValues(enumTypeName) {
|
|
236
236
|
try {
|
|
237
|
-
const enumQuery = `
|
|
238
|
-
SELECT e.enumlabel
|
|
239
|
-
FROM pg_enum e
|
|
240
|
-
JOIN pg_type t ON e.enumtypid = t.oid
|
|
241
|
-
WHERE t.typname = $1
|
|
242
|
-
ORDER BY e.enumsortorder
|
|
237
|
+
const enumQuery = `
|
|
238
|
+
SELECT e.enumlabel
|
|
239
|
+
FROM pg_enum e
|
|
240
|
+
JOIN pg_type t ON e.enumtypid = t.oid
|
|
241
|
+
WHERE t.typname = $1
|
|
242
|
+
ORDER BY e.enumsortorder
|
|
243
243
|
`;
|
|
244
244
|
const result = await this.targetPool.query(enumQuery, [enumTypeName]);
|
|
245
245
|
return result.rows.map((row) => row.enumlabel);
|
|
@@ -139,11 +139,11 @@ program
|
|
|
139
139
|
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
140
140
|
async function checkIfTablesExist(pool) {
|
|
141
141
|
try {
|
|
142
|
-
const result = await pool.query(`
|
|
143
|
-
SELECT COUNT(*)
|
|
144
|
-
FROM information_schema.tables
|
|
145
|
-
WHERE table_schema = 'public'
|
|
146
|
-
AND table_type = 'BASE TABLE'
|
|
142
|
+
const result = await pool.query(`
|
|
143
|
+
SELECT COUNT(*)
|
|
144
|
+
FROM information_schema.tables
|
|
145
|
+
WHERE table_schema = 'public'
|
|
146
|
+
AND table_type = 'BASE TABLE'
|
|
147
147
|
`);
|
|
148
148
|
return parseInt(result.rows[0].count) > 0;
|
|
149
149
|
}
|
|
@@ -28,11 +28,11 @@ async function main() {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
async function getTablesFromDatabase(pool) {
|
|
31
|
-
const query = `
|
|
32
|
-
SELECT table_name
|
|
33
|
-
FROM information_schema.tables
|
|
34
|
-
WHERE table_schema = 'public'
|
|
35
|
-
AND table_type = 'BASE TABLE'
|
|
31
|
+
const query = `
|
|
32
|
+
SELECT table_name
|
|
33
|
+
FROM information_schema.tables
|
|
34
|
+
WHERE table_schema = 'public'
|
|
35
|
+
AND table_type = 'BASE TABLE'
|
|
36
36
|
`;
|
|
37
37
|
const result = await pool.query(query);
|
|
38
38
|
return result.rows.map(row => row.table_name);
|
|
@@ -61,19 +61,19 @@ async function generateSyncScript(sourcePool, targetPool, sourceTables, targetTa
|
|
|
61
61
|
return script;
|
|
62
62
|
}
|
|
63
63
|
async function getTableColumns(pool, table) {
|
|
64
|
-
const query = `
|
|
65
|
-
SELECT
|
|
66
|
-
column_name,
|
|
67
|
-
data_type,
|
|
68
|
-
is_nullable,
|
|
69
|
-
column_default
|
|
70
|
-
FROM
|
|
71
|
-
information_schema.columns
|
|
72
|
-
WHERE
|
|
73
|
-
table_schema = 'public'
|
|
74
|
-
AND table_name = $1
|
|
75
|
-
ORDER BY
|
|
76
|
-
ordinal_position
|
|
64
|
+
const query = `
|
|
65
|
+
SELECT
|
|
66
|
+
column_name,
|
|
67
|
+
data_type,
|
|
68
|
+
is_nullable,
|
|
69
|
+
column_default
|
|
70
|
+
FROM
|
|
71
|
+
information_schema.columns
|
|
72
|
+
WHERE
|
|
73
|
+
table_schema = 'public'
|
|
74
|
+
AND table_name = $1
|
|
75
|
+
ORDER BY
|
|
76
|
+
ordinal_position
|
|
77
77
|
`;
|
|
78
78
|
const result = await pool.query(query, [table]);
|
|
79
79
|
return result.rows;
|