Keep/keep-notes/scripts/fix-order.ts

35 lines
758 B
TypeScript

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function fixOrder() {
try {
// Get all notes sorted by creation date
const notes = await prisma.note.findMany({
orderBy: [
{ isPinned: 'desc' },
{ createdAt: 'asc' }
]
})
console.log(`Found ${notes.length} notes`)
// Update order values
for (let i = 0; i < notes.length; i++) {
await prisma.note.update({
where: { id: notes[i].id },
data: { order: i }
})
console.log(`Updated note ${notes[i].id} - order: ${i}`)
}
console.log('✅ Order values fixed!')
} catch (error) {
console.error('Error:', error)
} finally {
await prisma.$disconnect()
}
}
fixOrder()