@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.
Files changed (170) hide show
  1. package/.github/CODEOWNERS +1 -1
  2. package/README.md +269 -269
  3. package/migration-config.json +63 -63
  4. package/migration-config.json.bk +95 -95
  5. package/migrations/add_reserved_amount.sql +7 -7
  6. package/package.json +44 -44
  7. package/prisma/migrations/add_uuid_to_transactions.sql +13 -13
  8. package/prisma/schema.prisma +609 -607
  9. package/src/index.ts +23 -23
  10. package/src/prisma-factory.service.ts +40 -40
  11. package/src/prisma.module.ts +9 -9
  12. package/src/prisma.service.ts +16 -16
  13. package/src/scripts/add-uuid-to-table.ts +138 -138
  14. package/src/scripts/create-tenant-schemas.ts +145 -145
  15. package/src/scripts/data-migration/batch-migrator.ts +248 -248
  16. package/src/scripts/data-migration/data-transformer.ts +426 -426
  17. package/src/scripts/data-migration/db-connector.ts +120 -120
  18. package/src/scripts/data-migration/dependency-resolver.ts +174 -174
  19. package/src/scripts/data-migration/entity-discovery.ts +196 -196
  20. package/src/scripts/data-migration/foreign-key-manager.ts +277 -277
  21. package/src/scripts/data-migration/migration-config.json +63 -63
  22. package/src/scripts/data-migration/migration-tool.ts +509 -509
  23. package/src/scripts/data-migration/schema-utils.ts +248 -248
  24. package/src/scripts/data-migration/tenant-migrator.ts +201 -201
  25. package/src/scripts/data-migration/typecast-manager.ts +193 -193
  26. package/src/scripts/data-migration/types.ts +113 -113
  27. package/src/scripts/database-initializer.ts +49 -49
  28. package/src/scripts/drop-database.ts +104 -104
  29. package/src/scripts/dump-source-db.sh +61 -61
  30. package/src/scripts/encrypt-user-passwords.ts +36 -36
  31. package/src/scripts/error-handler.ts +117 -117
  32. package/src/scripts/fix-data-types.ts +241 -241
  33. package/src/scripts/fix-enum-values.ts +357 -357
  34. package/src/scripts/fix-schema-discrepancies.ts +317 -317
  35. package/src/scripts/fix-table-indexes.ts +601 -601
  36. package/src/scripts/migrate-schema-structure.ts +90 -90
  37. package/src/scripts/migrate-uuid.ts +76 -76
  38. package/src/scripts/post-migration-validator.ts +526 -526
  39. package/src/scripts/pre-migration-validator.ts +610 -610
  40. package/src/scripts/reset-database.ts +263 -263
  41. package/src/scripts/retry-failed-migrations.ts +416 -416
  42. package/src/scripts/run-migration.ts +707 -707
  43. package/src/scripts/schema-sync.ts +128 -128
  44. package/src/scripts/sequence-sync-cli.ts +416 -416
  45. package/src/scripts/sequence-synchronizer.ts +127 -127
  46. package/src/scripts/sync-enum-types.ts +170 -170
  47. package/src/scripts/sync-enum-values.ts +563 -563
  48. package/src/scripts/truncate-database.ts +123 -123
  49. package/src/scripts/verify-migration-setup.ts +135 -135
  50. package/tsconfig.json +17 -17
  51. package/dist/index.d.ts +0 -7
  52. package/dist/index.js +0 -34
  53. package/dist/index.js.map +0 -1
  54. package/dist/prisma-factory.service.d.ts +0 -9
  55. package/dist/prisma-factory.service.js +0 -47
  56. package/dist/prisma-factory.service.js.map +0 -1
  57. package/dist/prisma.module.d.ts +0 -2
  58. package/dist/prisma.module.js +0 -23
  59. package/dist/prisma.module.js.map +0 -1
  60. package/dist/prisma.service.d.ts +0 -6
  61. package/dist/prisma.service.js +0 -27
  62. package/dist/prisma.service.js.map +0 -1
  63. package/dist/scripts/add-uuid-to-table.d.ts +0 -8
  64. package/dist/scripts/add-uuid-to-table.js +0 -98
  65. package/dist/scripts/add-uuid-to-table.js.map +0 -1
  66. package/dist/scripts/create-tenant-schemas.d.ts +0 -1
  67. package/dist/scripts/create-tenant-schemas.js +0 -117
  68. package/dist/scripts/create-tenant-schemas.js.map +0 -1
  69. package/dist/scripts/data-migration/batch-migrator.d.ts +0 -20
  70. package/dist/scripts/data-migration/batch-migrator.js +0 -134
  71. package/dist/scripts/data-migration/batch-migrator.js.map +0 -1
  72. package/dist/scripts/data-migration/data-transformer.d.ts +0 -26
  73. package/dist/scripts/data-migration/data-transformer.js +0 -278
  74. package/dist/scripts/data-migration/data-transformer.js.map +0 -1
  75. package/dist/scripts/data-migration/db-connector.d.ts +0 -12
  76. package/dist/scripts/data-migration/db-connector.js +0 -94
  77. package/dist/scripts/data-migration/db-connector.js.map +0 -1
  78. package/dist/scripts/data-migration/dependency-resolver.d.ts +0 -18
  79. package/dist/scripts/data-migration/dependency-resolver.js +0 -132
  80. package/dist/scripts/data-migration/dependency-resolver.js.map +0 -1
  81. package/dist/scripts/data-migration/entity-discovery.d.ts +0 -11
  82. package/dist/scripts/data-migration/entity-discovery.js +0 -152
  83. package/dist/scripts/data-migration/entity-discovery.js.map +0 -1
  84. package/dist/scripts/data-migration/foreign-key-manager.d.ts +0 -18
  85. package/dist/scripts/data-migration/foreign-key-manager.js +0 -160
  86. package/dist/scripts/data-migration/foreign-key-manager.js.map +0 -1
  87. package/dist/scripts/data-migration/migration-tool.d.ts +0 -48
  88. package/dist/scripts/data-migration/migration-tool.js +0 -290
  89. package/dist/scripts/data-migration/migration-tool.js.map +0 -1
  90. package/dist/scripts/data-migration/schema-utils.d.ts +0 -18
  91. package/dist/scripts/data-migration/schema-utils.js +0 -207
  92. package/dist/scripts/data-migration/schema-utils.js.map +0 -1
  93. package/dist/scripts/data-migration/tenant-migrator.d.ts +0 -15
  94. package/dist/scripts/data-migration/tenant-migrator.js +0 -117
  95. package/dist/scripts/data-migration/tenant-migrator.js.map +0 -1
  96. package/dist/scripts/data-migration/typecast-manager.d.ts +0 -9
  97. package/dist/scripts/data-migration/typecast-manager.js +0 -179
  98. package/dist/scripts/data-migration/typecast-manager.js.map +0 -1
  99. package/dist/scripts/data-migration/types.d.ts +0 -100
  100. package/dist/scripts/data-migration/types.js +0 -3
  101. package/dist/scripts/data-migration/types.js.map +0 -1
  102. package/dist/scripts/database-initializer.d.ts +0 -5
  103. package/dist/scripts/database-initializer.js +0 -45
  104. package/dist/scripts/database-initializer.js.map +0 -1
  105. package/dist/scripts/drop-database.d.ts +0 -10
  106. package/dist/scripts/drop-database.js +0 -81
  107. package/dist/scripts/drop-database.js.map +0 -1
  108. package/dist/scripts/encrypt-user-passwords.d.ts +0 -1
  109. package/dist/scripts/encrypt-user-passwords.js +0 -33
  110. package/dist/scripts/encrypt-user-passwords.js.map +0 -1
  111. package/dist/scripts/error-handler.d.ts +0 -12
  112. package/dist/scripts/error-handler.js +0 -82
  113. package/dist/scripts/error-handler.js.map +0 -1
  114. package/dist/scripts/fix-data-types.d.ts +0 -10
  115. package/dist/scripts/fix-data-types.js +0 -185
  116. package/dist/scripts/fix-data-types.js.map +0 -1
  117. package/dist/scripts/fix-enum-values.d.ts +0 -17
  118. package/dist/scripts/fix-enum-values.js +0 -234
  119. package/dist/scripts/fix-enum-values.js.map +0 -1
  120. package/dist/scripts/fix-schema-discrepancies.d.ts +0 -21
  121. package/dist/scripts/fix-schema-discrepancies.js +0 -240
  122. package/dist/scripts/fix-schema-discrepancies.js.map +0 -1
  123. package/dist/scripts/fix-table-indexes.d.ts +0 -26
  124. package/dist/scripts/fix-table-indexes.js +0 -460
  125. package/dist/scripts/fix-table-indexes.js.map +0 -1
  126. package/dist/scripts/migrate-schema-structure.d.ts +0 -1
  127. package/dist/scripts/migrate-schema-structure.js +0 -76
  128. package/dist/scripts/migrate-schema-structure.js.map +0 -1
  129. package/dist/scripts/migrate-uuid.d.ts +0 -2
  130. package/dist/scripts/migrate-uuid.js +0 -57
  131. package/dist/scripts/migrate-uuid.js.map +0 -1
  132. package/dist/scripts/post-migration-validator.d.ts +0 -34
  133. package/dist/scripts/post-migration-validator.js +0 -363
  134. package/dist/scripts/post-migration-validator.js.map +0 -1
  135. package/dist/scripts/pre-migration-validator.d.ts +0 -25
  136. package/dist/scripts/pre-migration-validator.js +0 -491
  137. package/dist/scripts/pre-migration-validator.js.map +0 -1
  138. package/dist/scripts/reset-database.d.ts +0 -17
  139. package/dist/scripts/reset-database.js +0 -202
  140. package/dist/scripts/reset-database.js.map +0 -1
  141. package/dist/scripts/retry-failed-migrations.d.ts +0 -14
  142. package/dist/scripts/retry-failed-migrations.js +0 -301
  143. package/dist/scripts/retry-failed-migrations.js.map +0 -1
  144. package/dist/scripts/run-migration.d.ts +0 -1
  145. package/dist/scripts/run-migration.js +0 -512
  146. package/dist/scripts/run-migration.js.map +0 -1
  147. package/dist/scripts/schema-sync.d.ts +0 -1
  148. package/dist/scripts/schema-sync.js +0 -85
  149. package/dist/scripts/schema-sync.js.map +0 -1
  150. package/dist/scripts/sequence-sync-cli.d.ts +0 -2
  151. package/dist/scripts/sequence-sync-cli.js +0 -287
  152. package/dist/scripts/sequence-sync-cli.js.map +0 -1
  153. package/dist/scripts/sequence-synchronizer.d.ts +0 -8
  154. package/dist/scripts/sequence-synchronizer.js +0 -88
  155. package/dist/scripts/sequence-synchronizer.js.map +0 -1
  156. package/dist/scripts/sync-enum-types.d.ts +0 -13
  157. package/dist/scripts/sync-enum-types.js +0 -139
  158. package/dist/scripts/sync-enum-types.js.map +0 -1
  159. package/dist/scripts/sync-enum-values.d.ts +0 -20
  160. package/dist/scripts/sync-enum-values.js +0 -336
  161. package/dist/scripts/sync-enum-values.js.map +0 -1
  162. package/dist/scripts/truncate-database.d.ts +0 -10
  163. package/dist/scripts/truncate-database.js +0 -100
  164. package/dist/scripts/truncate-database.js.map +0 -1
  165. package/dist/scripts/verify-migration-setup.d.ts +0 -11
  166. package/dist/scripts/verify-migration-setup.js +0 -120
  167. package/dist/scripts/verify-migration-setup.js.map +0 -1
  168. package/dist/tsconfig.tsbuildinfo +0 -1
  169. package/prisma/migrations/add_athena_match_fields.sql +0 -18
  170. package/prisma/migrations/add_bank_receipt_number.sql +0 -9
@@ -1,90 +1,90 @@
1
- import { PrismaClient } from "@prisma/client";
2
- import { exec } from "child_process";
3
- import { promisify } from "util";
4
- import * as dotenv from "dotenv";
5
-
6
- dotenv.config();
7
-
8
- const execAsync = promisify(exec);
9
-
10
- async function migrateSchemaStructure() {
11
- const sourcePrisma = new PrismaClient({
12
- datasources: {
13
- db: {
14
- url: process.env.SOURCE_DATABASE_URL,
15
- },
16
- },
17
- });
18
-
19
- const targetPrisma = new PrismaClient({
20
- datasources: {
21
- db: {
22
- url: process.env.DATABASE_URL,
23
- },
24
- },
25
- });
26
-
27
- try {
28
- console.log("Fetching API keys and creating schemas...");
29
-
30
- const apiKeys = await sourcePrisma.api_keys.findMany({
31
- select: {
32
- api_key: true,
33
- providers: {
34
- select: {
35
- name: true,
36
- },
37
- },
38
- },
39
- });
40
-
41
- for (const apiKey of apiKeys) {
42
- const schemaName = apiKey.api_key;
43
-
44
- // Create schema if it doesn't exist
45
- await targetPrisma.$executeRawUnsafe(
46
- `CREATE SCHEMA IF NOT EXISTS "${schemaName}"`
47
- );
48
-
49
- // Apply schema structure using prisma db push
50
- const dbUrl = `${process.env.DATABASE_URL}?schema=${schemaName}`;
51
- await execAsync(
52
- `DATABASE_URL="${dbUrl}" npx prisma db push --schema ./prisma/schema.prisma --skip-generate`
53
- );
54
-
55
- // Verify schema creation
56
- const schemaExists = await checkSchemaExists(schemaName);
57
- if (!schemaExists) {
58
- throw new Error(`Failed to create schema ${schemaName}`);
59
- }
60
- }
61
-
62
- console.log("Schema structure migration completed successfully");
63
- } catch (error) {
64
- console.error("Error in schema migration process:", error);
65
- throw error; // Propagate error to handle it in the calling function
66
- } finally {
67
- await sourcePrisma.$disconnect();
68
- await targetPrisma.$disconnect();
69
- }
70
- }
71
-
72
- async function checkSchemaExists(schemaName: string): Promise<boolean> {
73
- const prisma = new PrismaClient();
74
- try {
75
- const result = await prisma.$queryRaw`
76
- SELECT schema_name
77
- FROM information_schema.schemata
78
- WHERE schema_name = ${schemaName}
79
- `;
80
-
81
- return Array.isArray(result) && result.length > 0;
82
- } catch (error) {
83
- console.error(`Error checking if schema exists: ${error}`);
84
- return false;
85
- } finally {
86
- await prisma.$disconnect();
87
- }
88
- }
89
-
90
- migrateSchemaStructure().catch(console.error);
1
+ import { PrismaClient } from "@prisma/client";
2
+ import { exec } from "child_process";
3
+ import { promisify } from "util";
4
+ import * as dotenv from "dotenv";
5
+
6
+ dotenv.config();
7
+
8
+ const execAsync = promisify(exec);
9
+
10
+ async function migrateSchemaStructure() {
11
+ const sourcePrisma = new PrismaClient({
12
+ datasources: {
13
+ db: {
14
+ url: process.env.SOURCE_DATABASE_URL,
15
+ },
16
+ },
17
+ });
18
+
19
+ const targetPrisma = new PrismaClient({
20
+ datasources: {
21
+ db: {
22
+ url: process.env.DATABASE_URL,
23
+ },
24
+ },
25
+ });
26
+
27
+ try {
28
+ console.log("Fetching API keys and creating schemas...");
29
+
30
+ const apiKeys = await sourcePrisma.api_keys.findMany({
31
+ select: {
32
+ api_key: true,
33
+ providers: {
34
+ select: {
35
+ name: true,
36
+ },
37
+ },
38
+ },
39
+ });
40
+
41
+ for (const apiKey of apiKeys) {
42
+ const schemaName = apiKey.api_key;
43
+
44
+ // Create schema if it doesn't exist
45
+ await targetPrisma.$executeRawUnsafe(
46
+ `CREATE SCHEMA IF NOT EXISTS "${schemaName}"`
47
+ );
48
+
49
+ // Apply schema structure using prisma db push
50
+ const dbUrl = `${process.env.DATABASE_URL}?schema=${schemaName}`;
51
+ await execAsync(
52
+ `DATABASE_URL="${dbUrl}" npx prisma db push --schema ./prisma/schema.prisma --skip-generate`
53
+ );
54
+
55
+ // Verify schema creation
56
+ const schemaExists = await checkSchemaExists(schemaName);
57
+ if (!schemaExists) {
58
+ throw new Error(`Failed to create schema ${schemaName}`);
59
+ }
60
+ }
61
+
62
+ console.log("Schema structure migration completed successfully");
63
+ } catch (error) {
64
+ console.error("Error in schema migration process:", error);
65
+ throw error; // Propagate error to handle it in the calling function
66
+ } finally {
67
+ await sourcePrisma.$disconnect();
68
+ await targetPrisma.$disconnect();
69
+ }
70
+ }
71
+
72
+ async function checkSchemaExists(schemaName: string): Promise<boolean> {
73
+ const prisma = new PrismaClient();
74
+ try {
75
+ const result = await prisma.$queryRaw`
76
+ SELECT schema_name
77
+ FROM information_schema.schemata
78
+ WHERE schema_name = ${schemaName}
79
+ `;
80
+
81
+ return Array.isArray(result) && result.length > 0;
82
+ } catch (error) {
83
+ console.error(`Error checking if schema exists: ${error}`);
84
+ return false;
85
+ } finally {
86
+ await prisma.$disconnect();
87
+ }
88
+ }
89
+
90
+ migrateSchemaStructure().catch(console.error);
@@ -1,76 +1,76 @@
1
- import { addUuidToTable } from "./add-uuid-to-table";
2
- import { PrismaClient } from "@prisma/client";
3
-
4
- const prisma = new PrismaClient();
5
-
6
- async function migrateUuid() {
7
- try {
8
- console.log("🚀 Iniciando migración de UUID...");
9
-
10
- // 0. Habilitar la extensión uuid-ossp
11
- console.log("\n📦 Habilitando extensión uuid-ossp...");
12
- await prisma.$executeRaw`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`;
13
-
14
- // 1. Verificar registros sin UUID
15
- console.log("\n🔍 Verificando registros sin UUID...");
16
- const nullUuids = await prisma.$queryRaw`
17
- SELECT COUNT(*) as count
18
- FROM transactions
19
- WHERE uuid IS NULL;
20
- `;
21
-
22
- if (nullUuids[0].count > 0) {
23
- console.log(
24
- `\n📝 Actualizando ${nullUuids[0].count} registros sin UUID...`
25
- );
26
- await prisma.$executeRaw`
27
- UPDATE transactions
28
- SET uuid = uuid_generate_v4()
29
- WHERE uuid IS NULL;
30
- `;
31
- }
32
-
33
- // 2. Verificar nuevamente que todos los registros tienen UUID
34
- console.log("\n🔍 Verificando registros después de la actualización...");
35
- const remainingNullUuids = await prisma.$queryRaw`
36
- SELECT COUNT(*) as count
37
- FROM transactions
38
- WHERE uuid IS NULL;
39
- `;
40
-
41
- if (remainingNullUuids[0].count > 0) {
42
- throw new Error(
43
- `Aún hay ${remainingNullUuids[0].count} registros sin UUID después de la actualización`
44
- );
45
- }
46
-
47
- // 3. Hacer UUID requerido y añadir valor por defecto
48
- console.log(
49
- "\n📝 Haciendo UUID requerido y añadiendo valor por defecto..."
50
- );
51
- await prisma.$executeRaw`
52
- ALTER TABLE transactions
53
- ALTER COLUMN uuid SET NOT NULL;
54
- `;
55
-
56
- await prisma.$executeRaw`
57
- ALTER TABLE transactions
58
- ALTER COLUMN uuid
59
- SET DEFAULT uuid_generate_v4();
60
- `;
61
-
62
- console.log("\n✅ Migración completada exitosamente");
63
- } catch (error) {
64
- console.error("\n❌ Error durante la migración:", error);
65
- process.exit(1);
66
- } finally {
67
- await prisma.$disconnect();
68
- }
69
- }
70
-
71
- // Ejecutar la migración
72
- if (require.main === module) {
73
- migrateUuid();
74
- }
75
-
76
- export { migrateUuid };
1
+ import { addUuidToTable } from "./add-uuid-to-table";
2
+ import { PrismaClient } from "@prisma/client";
3
+
4
+ const prisma = new PrismaClient();
5
+
6
+ async function migrateUuid() {
7
+ try {
8
+ console.log("🚀 Iniciando migración de UUID...");
9
+
10
+ // 0. Habilitar la extensión uuid-ossp
11
+ console.log("\n📦 Habilitando extensión uuid-ossp...");
12
+ await prisma.$executeRaw`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`;
13
+
14
+ // 1. Verificar registros sin UUID
15
+ console.log("\n🔍 Verificando registros sin UUID...");
16
+ const nullUuids = await prisma.$queryRaw`
17
+ SELECT COUNT(*) as count
18
+ FROM transactions
19
+ WHERE uuid IS NULL;
20
+ `;
21
+
22
+ if (nullUuids[0].count > 0) {
23
+ console.log(
24
+ `\n📝 Actualizando ${nullUuids[0].count} registros sin UUID...`
25
+ );
26
+ await prisma.$executeRaw`
27
+ UPDATE transactions
28
+ SET uuid = uuid_generate_v4()
29
+ WHERE uuid IS NULL;
30
+ `;
31
+ }
32
+
33
+ // 2. Verificar nuevamente que todos los registros tienen UUID
34
+ console.log("\n🔍 Verificando registros después de la actualización...");
35
+ const remainingNullUuids = await prisma.$queryRaw`
36
+ SELECT COUNT(*) as count
37
+ FROM transactions
38
+ WHERE uuid IS NULL;
39
+ `;
40
+
41
+ if (remainingNullUuids[0].count > 0) {
42
+ throw new Error(
43
+ `Aún hay ${remainingNullUuids[0].count} registros sin UUID después de la actualización`
44
+ );
45
+ }
46
+
47
+ // 3. Hacer UUID requerido y añadir valor por defecto
48
+ console.log(
49
+ "\n📝 Haciendo UUID requerido y añadiendo valor por defecto..."
50
+ );
51
+ await prisma.$executeRaw`
52
+ ALTER TABLE transactions
53
+ ALTER COLUMN uuid SET NOT NULL;
54
+ `;
55
+
56
+ await prisma.$executeRaw`
57
+ ALTER TABLE transactions
58
+ ALTER COLUMN uuid
59
+ SET DEFAULT uuid_generate_v4();
60
+ `;
61
+
62
+ console.log("\n✅ Migración completada exitosamente");
63
+ } catch (error) {
64
+ console.error("\n❌ Error durante la migración:", error);
65
+ process.exit(1);
66
+ } finally {
67
+ await prisma.$disconnect();
68
+ }
69
+ }
70
+
71
+ // Ejecutar la migración
72
+ if (require.main === module) {
73
+ migrateUuid();
74
+ }
75
+
76
+ export { migrateUuid };