mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
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:
@@ -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) {}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user