fix(server): session updated at (#13099)

fix AI-325

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Improved database handling for session update times to ensure more
accurate tracking of session activity.
* Enhanced migration process to better manage and update session
metadata.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-07-08 21:16:56 +08:00
committed by GitHub
parent 072fff1460
commit 0bd1f10498
3 changed files with 40 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
import { PrismaClient } from '@prisma/client';
type SessionTime = {
sessionId: string;
_max: {
createdAt: Date;
};
};
export class CorrectSessionUpdateTime1751966744168 {
// do the migration
static async up(db: PrismaClient) {
const sessionTime = await db.aiSessionMessage.groupBy({
by: ['sessionId'],
_max: {
createdAt: true,
},
});
await Promise.all(
sessionTime
.filter((s): s is SessionTime => !!s._max.createdAt)
.map(s =>
db.aiSession.update({
where: { id: s.sessionId },
data: { updatedAt: s._max.createdAt },
})
)
);
}
// revert the migration
static async down(_db: PrismaClient) {}
}

View File

@@ -6,3 +6,4 @@ export * from './1732861452428-migrate-invite-status';
export * from './1733125339942-universal-subscription';
export * from './1738590347632-feature-redundant';
export * from './1745211351719-create-indexer-tables';
export * from './1751966744168-correct-session-update-time';