Skip to content

Commit 88e4c8a

Browse files
Merge pull request #758 from sparrowapp-dev/development
Release Version 2.29.0 [Merging development into prod]
2 parents 1df12d4 + aae1bd8 commit 88e4c8a

27 files changed

+1520
-149
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,5 @@ STRIPE_SECRET_KEY= # Stripe secret key (backend - KEEP SECURE!)
121121

122122
# [Sparrow Admin]
123123
SPARROW_ADMIN_KEY= # Sparrow admin key for privileged operations specific to Sparrow team
124-
ADMIN_BASE_URL= # Base URL for Sparrow admin operations
124+
ADMIN_BASE_URL= # Base URL for Sparrow admin operations
125+
STAKEHOLDERS_EMAIL_LIST= # Comma-separated list of sparrow admin emails

deploymentManifests/deployment.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ spec:
340340
valueFrom:
341341
secretKeyRef:
342342
name: sparrow-api-secret
343-
key: DEEPSEEK_API_MODEL
343+
key: DEEPSEEK_API_MODEL
344344
- name: DB_NAME
345345
valueFrom:
346346
secretKeyRef:
@@ -381,6 +381,11 @@ spec:
381381
secretKeyRef:
382382
name: sparrow-api-secret
383383
key: ADMIN_BASE_URL
384+
- name: STAKEHOLDERS_EMAIL_LIST
385+
valueFrom:
386+
secretKeyRef:
387+
name: sparrow-api-secret
388+
key: STAKEHOLDERS_EMAIL_LIST
384389

385390
---
386391
apiVersion: v1

deploymentManifests/release-v2.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ spec:
309309
valueFrom:
310310
secretKeyRef:
311311
name: release-api-v2-secret
312-
key: DEEPSEEK_API_MODEL
312+
key: DEEPSEEK_API_MODEL
313313
- name: DB_NAME
314314
valueFrom:
315315
secretKeyRef:
@@ -350,6 +350,11 @@ spec:
350350
secretKeyRef:
351351
name: release-api-v2-secret
352352
key: ADMIN_BASE_URL
353+
- name: STAKEHOLDERS_EMAIL_LIST
354+
valueFrom:
355+
secretKeyRef:
356+
name: release-api-v2-secret
357+
key: STAKEHOLDERS_EMAIL_LIST
353358

354359
---
355360
apiVersion: v1

migrations/ai-emailId.migration.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Inject, Injectable, OnModuleInit } from "@nestjs/common";
2+
import { Db, ObjectId } from "mongodb";
3+
import { Collections } from "@src/modules/common/enum/database.collection.enum";
4+
5+
@Injectable()
6+
export class AIlogsEmailIdMigration implements OnModuleInit {
7+
private hasRun = false;
8+
9+
constructor(
10+
@Inject("DATABASE_CONNECTION") private db: Db,
11+
) {}
12+
13+
async onModuleInit(): Promise<void> {
14+
if (this.hasRun) return;
15+
16+
try {
17+
console.log(`\n[Nest] Executing AIlogs emailId migration...`);
18+
19+
const aiLogsCollection = this.db.collection(Collections.AILOGS);
20+
const userCollection = this.db.collection(Collections.USER);
21+
22+
// Get docs where emailId is missing, null, or empty string
23+
const cursor = aiLogsCollection.find({
24+
$or: [
25+
{ emailId: { $exists: false } },
26+
{ emailId: null },
27+
{ emailId: "" }
28+
]
29+
});
30+
31+
let updatedCount = 0;
32+
33+
while (await cursor.hasNext()) {
34+
const doc = await cursor.next();
35+
if (!doc?.userId || doc.userId === "null") continue;
36+
37+
try {
38+
// Convert userId to ObjectId if valid
39+
const userId =
40+
typeof doc.userId === "string" && ObjectId.isValid(doc.userId)
41+
? new ObjectId(doc.userId)
42+
: doc.userId;
43+
44+
// Fetch user email
45+
const user = await userCollection.findOne(
46+
{ _id: userId },
47+
{ projection: { email: 1 } }
48+
);
49+
50+
if (!user?.email) continue;
51+
52+
// Update AIlogs document
53+
await aiLogsCollection.updateOne(
54+
{ _id: doc._id },
55+
{ $set: { emailId: user.email } }
56+
);
57+
58+
updatedCount++;
59+
} catch (err) {
60+
console.error(`Failed to update doc ${doc._id}:`, err.message);
61+
}
62+
}
63+
64+
console.log(`Updated ${updatedCount} AIlogs documents with emailId`);
65+
this.hasRun = true;
66+
console.log("Migration completed successfully. Exiting...");
67+
68+
process.exit(0);
69+
} catch (error) {
70+
console.error("Error during AIlogs emailId migration:", error);
71+
process.exit(1);
72+
}
73+
}
74+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"start:upgrade-plan": "ts-node -r tsconfig-paths/register src/upgrade-plan.ts",
3434
"start:migration-mock-url": "ts-node -r tsconfig-paths/register src/migrationMockRequestUrl.ts",
3535
"start:migration-hub-billing": "ts-node -r tsconfig-paths/register src/migrationHubBilling.ts",
36-
"start:migration-superadmin": "ts-node -r tsconfig-paths/register src/migration-superadmin.ts"
36+
"start:migration-superadmin": "ts-node -r tsconfig-paths/register src/migration-superadmin.ts",
37+
"start:migration-email": "ts-node -r tsconfig-paths/register src/migration-emailId.ts"
3738
},
3839
"dependencies": {
3940
"@anthropic-ai/sdk": "^0.54.0",
@@ -84,6 +85,7 @@
8485
"husky": "^8.0.3",
8586
"install": "^0.13.0",
8687
"js-yaml": "^4.1.0",
88+
"json2csv": "6.0.0-alpha.2",
8789
"jsonwebtoken": "^9.0.2",
8890
"mongodb": "^5.7.0",
8991
"nest-access-control": "2.2.0",
@@ -117,6 +119,7 @@
117119
"@types/gravatar": "1.8.3",
118120
"@types/jest": "^29.5.3",
119121
"@types/js-yaml": "^4.0.7",
122+
"@types/json2csv": "^5.0.7",
120123
"@types/jsonwebtoken": "^9.0.9",
121124
"@types/mime-types": "^3.0.1",
122125
"@types/node": "16.11.56",

0 commit comments

Comments
 (0)