@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.
Files changed (106) hide show
  1. package/.dockerignore +14 -0
  2. package/Dockerfile +23 -0
  3. package/README.md +269 -269
  4. package/dist/index.d.ts +1 -1
  5. package/dist/prisma.service.d.ts +1 -1
  6. package/dist/scripts/add-uuid-to-table.js +32 -32
  7. package/dist/scripts/data-migration/batch-migrator.js +12 -12
  8. package/dist/scripts/data-migration/data-transformer.js +14 -14
  9. package/dist/scripts/data-migration/dependency-resolver.js +23 -23
  10. package/dist/scripts/data-migration/entity-discovery.js +68 -68
  11. package/dist/scripts/data-migration/foreign-key-manager.js +23 -23
  12. package/dist/scripts/data-migration/migration-tool.js +5 -5
  13. package/dist/scripts/data-migration/schema-utils.js +74 -74
  14. package/dist/scripts/data-migration/typecast-manager.js +4 -4
  15. package/dist/scripts/database-initializer.js +5 -5
  16. package/dist/scripts/drop-database.js +5 -5
  17. package/dist/scripts/fix-data-types.js +53 -53
  18. package/dist/scripts/fix-enum-values.js +34 -34
  19. package/dist/scripts/fix-schema-discrepancies.js +40 -40
  20. package/dist/scripts/fix-table-indexes.js +81 -81
  21. package/dist/scripts/migrate-schema-structure.js +4 -4
  22. package/dist/scripts/migrate-uuid.js +19 -19
  23. package/dist/scripts/post-migration-validator.js +49 -49
  24. package/dist/scripts/pre-migration-validator.js +107 -107
  25. package/dist/scripts/reset-database.js +21 -21
  26. package/dist/scripts/retry-failed-migrations.js +28 -28
  27. package/dist/scripts/run-migration.js +5 -5
  28. package/dist/scripts/schema-sync.js +18 -18
  29. package/dist/scripts/sequence-sync-cli.js +55 -55
  30. package/dist/scripts/sequence-synchronizer.js +20 -20
  31. package/dist/scripts/sync-enum-types.js +30 -30
  32. package/dist/scripts/sync-enum-values.js +52 -52
  33. package/dist/scripts/truncate-database.js +10 -10
  34. package/dist/scripts/verify-migration-setup.js +10 -10
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/migration-config.json +63 -63
  37. package/migration-config.json.bk +95 -95
  38. package/package.json +44 -44
  39. package/prisma/migrations/add_accepts_partial_payments_to_users.sql +19 -0
  40. package/prisma/migrations/add_amount_received_to_manual_payments.sql +19 -0
  41. package/prisma/migrations/add_commission_fields.sql +33 -0
  42. package/prisma/migrations/add_uuid_to_transactions.sql +13 -13
  43. package/prisma/migrations/complete_partial_payments_migration.sql +53 -0
  44. package/prisma/migrations/create_settlements_table.sql +60 -0
  45. package/prisma/schema.prisma +56 -4
  46. package/src/index.ts +23 -23
  47. package/src/prisma-factory.service.ts +40 -40
  48. package/src/prisma.module.ts +9 -9
  49. package/src/prisma.service.ts +16 -16
  50. package/src/scripts/add-uuid-to-table.ts +138 -138
  51. package/src/scripts/create-tenant-schemas.ts +145 -145
  52. package/src/scripts/data-migration/batch-migrator.ts +248 -248
  53. package/src/scripts/data-migration/data-transformer.ts +426 -426
  54. package/src/scripts/data-migration/db-connector.ts +120 -120
  55. package/src/scripts/data-migration/dependency-resolver.ts +174 -174
  56. package/src/scripts/data-migration/entity-discovery.ts +196 -196
  57. package/src/scripts/data-migration/foreign-key-manager.ts +277 -277
  58. package/src/scripts/data-migration/migration-config.json +63 -63
  59. package/src/scripts/data-migration/migration-tool.ts +509 -509
  60. package/src/scripts/data-migration/schema-utils.ts +248 -248
  61. package/src/scripts/data-migration/tenant-migrator.ts +201 -201
  62. package/src/scripts/data-migration/typecast-manager.ts +193 -193
  63. package/src/scripts/data-migration/types.ts +113 -113
  64. package/src/scripts/database-initializer.ts +49 -49
  65. package/src/scripts/drop-database.ts +104 -104
  66. package/src/scripts/dump-source-db.sh +61 -61
  67. package/src/scripts/encrypt-user-passwords.ts +36 -36
  68. package/src/scripts/error-handler.ts +117 -117
  69. package/src/scripts/fix-data-types.ts +241 -241
  70. package/src/scripts/fix-enum-values.ts +357 -357
  71. package/src/scripts/fix-schema-discrepancies.ts +317 -317
  72. package/src/scripts/fix-table-indexes.ts +601 -601
  73. package/src/scripts/migrate-schema-structure.ts +90 -90
  74. package/src/scripts/migrate-uuid.ts +76 -76
  75. package/src/scripts/post-migration-validator.ts +526 -526
  76. package/src/scripts/pre-migration-validator.ts +610 -610
  77. package/src/scripts/reset-database.ts +263 -263
  78. package/src/scripts/retry-failed-migrations.ts +416 -416
  79. package/src/scripts/run-migration.ts +707 -707
  80. package/src/scripts/schema-sync.ts +128 -128
  81. package/src/scripts/sequence-sync-cli.ts +416 -416
  82. package/src/scripts/sequence-synchronizer.ts +127 -127
  83. package/src/scripts/sync-enum-types.ts +170 -170
  84. package/src/scripts/sync-enum-values.ts +563 -563
  85. package/src/scripts/truncate-database.ts +123 -123
  86. package/src/scripts/verify-migration-setup.ts +135 -135
  87. package/tsconfig.json +17 -17
  88. package/dist/scripts/data-migration/dependency-manager.d.ts +0 -9
  89. package/dist/scripts/data-migration/dependency-manager.js +0 -86
  90. package/dist/scripts/data-migration/dependency-manager.js.map +0 -1
  91. package/dist/scripts/data-migration/migration-config.json +0 -63
  92. package/dist/scripts/data-migration/migration-phases.d.ts +0 -5
  93. package/dist/scripts/data-migration/migration-phases.js +0 -55
  94. package/dist/scripts/data-migration/migration-phases.js.map +0 -1
  95. package/dist/scripts/data-migration/multi-source-migrator.d.ts +0 -17
  96. package/dist/scripts/data-migration/multi-source-migrator.js +0 -130
  97. package/dist/scripts/data-migration/multi-source-migrator.js.map +0 -1
  98. package/dist/scripts/data-migration/phase-generator.d.ts +0 -15
  99. package/dist/scripts/data-migration/phase-generator.js +0 -187
  100. package/dist/scripts/data-migration/phase-generator.js.map +0 -1
  101. package/dist/scripts/data-migration.d.ts +0 -22
  102. package/dist/scripts/data-migration.js +0 -593
  103. package/dist/scripts/data-migration.js.map +0 -1
  104. package/dist/scripts/multi-db-migration.d.ts +0 -1
  105. package/dist/scripts/multi-db-migration.js +0 -55
  106. package/dist/scripts/multi-db-migration.js.map +0 -1
@@ -1,146 +1,146 @@
1
- import { PrismaClient } from '@prisma/client';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
4
- import * as dotenv from 'dotenv';
5
-
6
- dotenv.config();
7
-
8
- async function createTenantSchemas() {
9
- // Crear cliente para la base de datos de origen
10
- const sourcePrisma = new PrismaClient({
11
- datasources: {
12
- db: {
13
- url: process.env.SOURCE_DATABASE_URL,
14
- },
15
- },
16
- });
17
-
18
- // Crear cliente para la base de datos de destino
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 from source database to create tenant schemas...');
29
-
30
- // Obtener todos los api_keys existentes de la base de datos de origen
31
- const apiKeys = await sourcePrisma.api_keys.findMany({
32
- select: {
33
- api_key: true,
34
- providers: {
35
- select: {
36
- name: true,
37
- },
38
- },
39
- },
40
- });
41
-
42
- console.log(`Found ${apiKeys.length} API keys to create schemas for.`);
43
-
44
- // Crear un archivo SQL para ejecutar las migraciones
45
- const sqlCommands: string[] = [];
46
-
47
- // Añadir comando para asegurar que el schema public existe
48
- sqlCommands.push('CREATE SCHEMA IF NOT EXISTS public;');
49
-
50
- // Para cada API key, crear un schema y migrar la estructura
51
- for (const apiKey of apiKeys) {
52
- const schemaName = apiKey.api_key;
53
- const providerName = apiKey.providers?.name || 'unknown';
54
-
55
- console.log(`Creating schema for ${providerName} with key ${schemaName}`);
56
-
57
- // Crear el schema si no existe
58
- sqlCommands.push(`CREATE SCHEMA IF NOT EXISTS "${schemaName}";`);
59
-
60
- // También crear el API key en la base de datos de destino si no existe
61
- try {
62
- const existingApiKey = await targetPrisma.api_keys.findUnique({
63
- where: { api_key: schemaName },
64
- });
65
-
66
- if (!existingApiKey) {
67
- console.log(`Creating API key record in target database for ${schemaName}`);
68
-
69
- // Obtener el registro completo de la base de datos de origen
70
- const sourceApiKeyFull = await sourcePrisma.api_keys.findUnique({
71
- where: { api_key: schemaName },
72
- include: {
73
- providers: true,
74
- users: true,
75
- },
76
- });
77
-
78
- if (sourceApiKeyFull) {
79
- // Primero asegurarse de que el provider existe
80
- let providerId = null;
81
- if (sourceApiKeyFull.provider_id) {
82
- const existingProvider = await targetPrisma.providers.findUnique({
83
- where: { provider_id: sourceApiKeyFull.provider_id },
84
- });
85
-
86
- if (!existingProvider && sourceApiKeyFull.providers) {
87
- // Crear el provider si no existe
88
- const newProvider = await targetPrisma.providers.create({
89
- data: {
90
- provider_id: sourceApiKeyFull.providers.provider_id,
91
- name: sourceApiKeyFull.providers.name,
92
- api_key: sourceApiKeyFull.providers.api_key,
93
- country_id: sourceApiKeyFull.providers.country_id,
94
- contact_email: sourceApiKeyFull.providers.contact_email,
95
- is_active: sourceApiKeyFull.providers.is_active,
96
- agreement: sourceApiKeyFull.providers.agreement,
97
- image: sourceApiKeyFull.providers.image,
98
- },
99
- });
100
- providerId = newProvider.provider_id;
101
- } else if (existingProvider) {
102
- providerId = existingProvider.provider_id;
103
- }
104
- }
105
-
106
- // Crear el API key en la base de datos de destino
107
- await targetPrisma.api_keys.create({
108
- data: {
109
- api_key: sourceApiKeyFull.api_key,
110
- name: sourceApiKeyFull.name,
111
- is_active: sourceApiKeyFull.is_active,
112
- user_id: sourceApiKeyFull.user_id,
113
- provider_id: providerId,
114
- },
115
- });
116
- }
117
- }
118
- } catch (error) {
119
- console.error(`Error creating API key in target database for ${schemaName}:`, error);
120
- }
121
- }
122
-
123
- // Ensure the directory exists
124
- const migrationsDir = path.join(__dirname, '../../../prisma/migrations');
125
- if (!fs.existsSync(migrationsDir)) {
126
- console.log(`Creating migrations directory: ${migrationsDir}`);
127
- fs.mkdirSync(migrationsDir, { recursive: true });
128
- }
129
-
130
- // Save SQL commands to file with absolute path for clarity
131
- const sqlFilePath = path.join(migrationsDir, 'tenant-schemas.sql');
132
- fs.writeFileSync(sqlFilePath, sqlCommands.join('\n'));
133
-
134
- // Log the absolute path for debugging
135
- console.log(`SQL commands written to ${path.resolve(sqlFilePath)}`);
136
- console.log('Run this SQL file against your database to create the schemas.');
137
-
138
- } catch (error) {
139
- console.error('Error creating tenant schemas:', error);
140
- } finally {
141
- await sourcePrisma.$disconnect();
142
- await targetPrisma.$disconnect();
143
- }
144
- }
145
-
1
+ import { PrismaClient } from '@prisma/client';
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+ import * as dotenv from 'dotenv';
5
+
6
+ dotenv.config();
7
+
8
+ async function createTenantSchemas() {
9
+ // Crear cliente para la base de datos de origen
10
+ const sourcePrisma = new PrismaClient({
11
+ datasources: {
12
+ db: {
13
+ url: process.env.SOURCE_DATABASE_URL,
14
+ },
15
+ },
16
+ });
17
+
18
+ // Crear cliente para la base de datos de destino
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 from source database to create tenant schemas...');
29
+
30
+ // Obtener todos los api_keys existentes de la base de datos de origen
31
+ const apiKeys = await sourcePrisma.api_keys.findMany({
32
+ select: {
33
+ api_key: true,
34
+ providers: {
35
+ select: {
36
+ name: true,
37
+ },
38
+ },
39
+ },
40
+ });
41
+
42
+ console.log(`Found ${apiKeys.length} API keys to create schemas for.`);
43
+
44
+ // Crear un archivo SQL para ejecutar las migraciones
45
+ const sqlCommands: string[] = [];
46
+
47
+ // Añadir comando para asegurar que el schema public existe
48
+ sqlCommands.push('CREATE SCHEMA IF NOT EXISTS public;');
49
+
50
+ // Para cada API key, crear un schema y migrar la estructura
51
+ for (const apiKey of apiKeys) {
52
+ const schemaName = apiKey.api_key;
53
+ const providerName = apiKey.providers?.name || 'unknown';
54
+
55
+ console.log(`Creating schema for ${providerName} with key ${schemaName}`);
56
+
57
+ // Crear el schema si no existe
58
+ sqlCommands.push(`CREATE SCHEMA IF NOT EXISTS "${schemaName}";`);
59
+
60
+ // También crear el API key en la base de datos de destino si no existe
61
+ try {
62
+ const existingApiKey = await targetPrisma.api_keys.findUnique({
63
+ where: { api_key: schemaName },
64
+ });
65
+
66
+ if (!existingApiKey) {
67
+ console.log(`Creating API key record in target database for ${schemaName}`);
68
+
69
+ // Obtener el registro completo de la base de datos de origen
70
+ const sourceApiKeyFull = await sourcePrisma.api_keys.findUnique({
71
+ where: { api_key: schemaName },
72
+ include: {
73
+ providers: true,
74
+ users: true,
75
+ },
76
+ });
77
+
78
+ if (sourceApiKeyFull) {
79
+ // Primero asegurarse de que el provider existe
80
+ let providerId = null;
81
+ if (sourceApiKeyFull.provider_id) {
82
+ const existingProvider = await targetPrisma.providers.findUnique({
83
+ where: { provider_id: sourceApiKeyFull.provider_id },
84
+ });
85
+
86
+ if (!existingProvider && sourceApiKeyFull.providers) {
87
+ // Crear el provider si no existe
88
+ const newProvider = await targetPrisma.providers.create({
89
+ data: {
90
+ provider_id: sourceApiKeyFull.providers.provider_id,
91
+ name: sourceApiKeyFull.providers.name,
92
+ api_key: sourceApiKeyFull.providers.api_key,
93
+ country_id: sourceApiKeyFull.providers.country_id,
94
+ contact_email: sourceApiKeyFull.providers.contact_email,
95
+ is_active: sourceApiKeyFull.providers.is_active,
96
+ agreement: sourceApiKeyFull.providers.agreement,
97
+ image: sourceApiKeyFull.providers.image,
98
+ },
99
+ });
100
+ providerId = newProvider.provider_id;
101
+ } else if (existingProvider) {
102
+ providerId = existingProvider.provider_id;
103
+ }
104
+ }
105
+
106
+ // Crear el API key en la base de datos de destino
107
+ await targetPrisma.api_keys.create({
108
+ data: {
109
+ api_key: sourceApiKeyFull.api_key,
110
+ name: sourceApiKeyFull.name,
111
+ is_active: sourceApiKeyFull.is_active,
112
+ user_id: sourceApiKeyFull.user_id,
113
+ provider_id: providerId,
114
+ },
115
+ });
116
+ }
117
+ }
118
+ } catch (error) {
119
+ console.error(`Error creating API key in target database for ${schemaName}:`, error);
120
+ }
121
+ }
122
+
123
+ // Ensure the directory exists
124
+ const migrationsDir = path.join(__dirname, '../../../prisma/migrations');
125
+ if (!fs.existsSync(migrationsDir)) {
126
+ console.log(`Creating migrations directory: ${migrationsDir}`);
127
+ fs.mkdirSync(migrationsDir, { recursive: true });
128
+ }
129
+
130
+ // Save SQL commands to file with absolute path for clarity
131
+ const sqlFilePath = path.join(migrationsDir, 'tenant-schemas.sql');
132
+ fs.writeFileSync(sqlFilePath, sqlCommands.join('\n'));
133
+
134
+ // Log the absolute path for debugging
135
+ console.log(`SQL commands written to ${path.resolve(sqlFilePath)}`);
136
+ console.log('Run this SQL file against your database to create the schemas.');
137
+
138
+ } catch (error) {
139
+ console.error('Error creating tenant schemas:', error);
140
+ } finally {
141
+ await sourcePrisma.$disconnect();
142
+ await targetPrisma.$disconnect();
143
+ }
144
+ }
145
+
146
146
  createTenantSchemas().catch(console.error);