@friggframework/core 2.0.0--canary.461.94d7ddb.0 → 2.0.0--canary.461.5c7c48f.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/handlers/workers/db-migration.js +45 -39
- package/package.json +5 -5
|
@@ -47,20 +47,15 @@ const {
|
|
|
47
47
|
ValidationError,
|
|
48
48
|
} = require('../../database/use-cases/run-database-migration-use-case');
|
|
49
49
|
const {
|
|
50
|
-
|
|
51
|
-
} = require('../../
|
|
52
|
-
const {
|
|
53
|
-
ProcessRepositoryPostgres,
|
|
54
|
-
} = require('../../integrations/repositories/process-repository-postgres');
|
|
50
|
+
MigrationStatusRepositoryS3,
|
|
51
|
+
} = require('../../database/repositories/migration-status-repository-s3');
|
|
55
52
|
|
|
56
53
|
// Inject prisma-runner as dependency
|
|
57
54
|
const prismaRunner = require('../../database/utils/prisma-runner');
|
|
58
55
|
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const processRepository = new ProcessRepositoryPostgres();
|
|
63
|
-
const updateProcessState = new UpdateProcessState({ processRepository });
|
|
56
|
+
// Use S3 repository for migration status tracking (no User table dependency)
|
|
57
|
+
const bucketName = process.env.S3_BUCKET_NAME || process.env.MIGRATION_STATUS_BUCKET;
|
|
58
|
+
const migrationStatusRepository = new MigrationStatusRepositoryS3(bucketName);
|
|
64
59
|
|
|
65
60
|
/**
|
|
66
61
|
* Sanitizes error messages to prevent credential leaks
|
|
@@ -100,10 +95,10 @@ function sanitizeDatabaseUrl(url) {
|
|
|
100
95
|
/**
|
|
101
96
|
* Extract migration parameters from SQS event or direct invocation
|
|
102
97
|
* @param {Object} event - Lambda event (SQS or direct)
|
|
103
|
-
* @returns {Object} Extracted parameters {
|
|
98
|
+
* @returns {Object} Extracted parameters { migrationId, dbType, stage }
|
|
104
99
|
*/
|
|
105
100
|
function extractMigrationParams(event) {
|
|
106
|
-
let
|
|
101
|
+
let migrationId = null;
|
|
107
102
|
let stage = null;
|
|
108
103
|
|
|
109
104
|
// Migration infrastructure is PostgreSQL-only, so hardcode dbType
|
|
@@ -113,27 +108,27 @@ function extractMigrationParams(event) {
|
|
|
113
108
|
if (event.Records && event.Records.length > 0) {
|
|
114
109
|
// SQS event - extract from message body
|
|
115
110
|
const message = JSON.parse(event.Records[0].body);
|
|
116
|
-
|
|
111
|
+
migrationId = message.migrationId;
|
|
117
112
|
stage = message.stage;
|
|
118
113
|
|
|
119
114
|
console.log('SQS event detected');
|
|
120
|
-
console.log(`
|
|
115
|
+
console.log(` Migration ID: ${migrationId}`);
|
|
121
116
|
console.log(` DB Type: ${dbType} (hardcoded - PostgreSQL-only)`);
|
|
122
117
|
console.log(` Stage: ${stage}`);
|
|
123
118
|
} else {
|
|
124
119
|
// Direct invocation - use event properties or environment variables
|
|
125
|
-
|
|
120
|
+
migrationId = event.migrationId || null;
|
|
126
121
|
stage = event.stage || process.env.STAGE || 'production';
|
|
127
122
|
|
|
128
123
|
console.log('Direct invocation detected');
|
|
129
|
-
if (
|
|
130
|
-
console.log(`
|
|
124
|
+
if (migrationId) {
|
|
125
|
+
console.log(` Migration ID: ${migrationId}`);
|
|
131
126
|
}
|
|
132
127
|
console.log(` DB Type: ${dbType} (hardcoded - PostgreSQL-only)`);
|
|
133
128
|
console.log(` Stage: ${stage}`);
|
|
134
129
|
}
|
|
135
130
|
|
|
136
|
-
return {
|
|
131
|
+
return { migrationId, dbType, stage };
|
|
137
132
|
}
|
|
138
133
|
|
|
139
134
|
/**
|
|
@@ -154,7 +149,7 @@ exports.handler = async (event, context) => {
|
|
|
154
149
|
}, null, 2));
|
|
155
150
|
|
|
156
151
|
// Extract migration parameters from event
|
|
157
|
-
const {
|
|
152
|
+
const { migrationId, dbType, stage } = extractMigrationParams(event);
|
|
158
153
|
|
|
159
154
|
// Get environment variables
|
|
160
155
|
const databaseUrl = process.env.DATABASE_URL;
|
|
@@ -178,10 +173,14 @@ exports.handler = async (event, context) => {
|
|
|
178
173
|
console.log(` Stage: ${stage}`);
|
|
179
174
|
console.log(` Database URL: ${sanitizeDatabaseUrl(databaseUrl)}`);
|
|
180
175
|
|
|
181
|
-
// Update
|
|
182
|
-
if (
|
|
183
|
-
console.log(`\n✓ Updating
|
|
184
|
-
await
|
|
176
|
+
// Update migration status to RUNNING (if migrationId provided)
|
|
177
|
+
if (migrationId) {
|
|
178
|
+
console.log(`\n✓ Updating migration status to RUNNING: ${migrationId}`);
|
|
179
|
+
await migrationStatusRepository.update({
|
|
180
|
+
migrationId,
|
|
181
|
+
stage,
|
|
182
|
+
state: 'RUNNING',
|
|
183
|
+
progress: 10,
|
|
185
184
|
startedAt: new Date().toISOString(),
|
|
186
185
|
});
|
|
187
186
|
}
|
|
@@ -212,10 +211,14 @@ exports.handler = async (event, context) => {
|
|
|
212
211
|
console.log(` Command: ${result.command}`);
|
|
213
212
|
console.log('========================================');
|
|
214
213
|
|
|
215
|
-
// Update
|
|
216
|
-
if (
|
|
217
|
-
console.log(`\n✓ Updating
|
|
218
|
-
await
|
|
214
|
+
// Update migration status to COMPLETED (if migrationId provided)
|
|
215
|
+
if (migrationId) {
|
|
216
|
+
console.log(`\n✓ Updating migration status to COMPLETED: ${migrationId}`);
|
|
217
|
+
await migrationStatusRepository.update({
|
|
218
|
+
migrationId,
|
|
219
|
+
stage,
|
|
220
|
+
state: 'COMPLETED',
|
|
221
|
+
progress: 100,
|
|
219
222
|
completedAt: new Date().toISOString(),
|
|
220
223
|
migrationCommand: result.command,
|
|
221
224
|
});
|
|
@@ -231,8 +234,8 @@ exports.handler = async (event, context) => {
|
|
|
231
234
|
timestamp: new Date().toISOString(),
|
|
232
235
|
};
|
|
233
236
|
|
|
234
|
-
if (
|
|
235
|
-
responseBody.
|
|
237
|
+
if (migrationId) {
|
|
238
|
+
responseBody.migrationId = migrationId;
|
|
236
239
|
}
|
|
237
240
|
|
|
238
241
|
return {
|
|
@@ -269,18 +272,21 @@ exports.handler = async (event, context) => {
|
|
|
269
272
|
// Sanitize error message before returning
|
|
270
273
|
const sanitizedError = sanitizeError(errorMessage);
|
|
271
274
|
|
|
272
|
-
// Update
|
|
273
|
-
if (
|
|
275
|
+
// Update migration status to FAILED (if migrationId provided)
|
|
276
|
+
if (migrationId) {
|
|
274
277
|
try {
|
|
275
|
-
console.log(`\n✓ Updating
|
|
276
|
-
await
|
|
277
|
-
|
|
278
|
+
console.log(`\n✓ Updating migration status to FAILED: ${migrationId}`);
|
|
279
|
+
await migrationStatusRepository.update({
|
|
280
|
+
migrationId,
|
|
281
|
+
stage,
|
|
282
|
+
state: 'FAILED',
|
|
283
|
+
progress: 0,
|
|
278
284
|
error: sanitizedError,
|
|
279
|
-
|
|
285
|
+
failedAt: new Date().toISOString(),
|
|
280
286
|
});
|
|
281
287
|
} catch (updateError) {
|
|
282
|
-
console.error('Failed to update
|
|
283
|
-
//
|
|
288
|
+
console.error('Failed to update migration status:', updateError.message);
|
|
289
|
+
// Continue - don't let status update failure block error response
|
|
284
290
|
}
|
|
285
291
|
}
|
|
286
292
|
|
|
@@ -292,8 +298,8 @@ exports.handler = async (event, context) => {
|
|
|
292
298
|
...(stage === 'dev' || stage === 'local' || stage === 'test' ? { stack: error.stack } : {}),
|
|
293
299
|
};
|
|
294
300
|
|
|
295
|
-
if (
|
|
296
|
-
errorBody.
|
|
301
|
+
if (migrationId) {
|
|
302
|
+
errorBody.migrationId = migrationId;
|
|
297
303
|
}
|
|
298
304
|
|
|
299
305
|
return {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.461.
|
|
4
|
+
"version": "2.0.0--canary.461.5c7c48f.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@friggframework/eslint-config": "2.0.0--canary.461.
|
|
41
|
-
"@friggframework/prettier-config": "2.0.0--canary.461.
|
|
42
|
-
"@friggframework/test": "2.0.0--canary.461.
|
|
40
|
+
"@friggframework/eslint-config": "2.0.0--canary.461.5c7c48f.0",
|
|
41
|
+
"@friggframework/prettier-config": "2.0.0--canary.461.5c7c48f.0",
|
|
42
|
+
"@friggframework/test": "2.0.0--canary.461.5c7c48f.0",
|
|
43
43
|
"@prisma/client": "^6.17.0",
|
|
44
44
|
"@types/lodash": "4.17.15",
|
|
45
45
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"publishConfig": {
|
|
80
80
|
"access": "public"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "5c7c48fd03d5cdb3897eb20b22c17a0e60a80b75"
|
|
83
83
|
}
|