Files
Momento/memento-note/scripts/migrate-embeddings.ts
Sepehr Ramezani e4d4e23dc7 chore: clean up repo for public release
- Remove BMAD framework, IDE configs, dev screenshots, test files,
  internal docs, and backup files
- Rename keep-notes/ to memento-note/
- Update all references from keep-notes to memento-note
- Add Apache 2.0 license with Commons Clause (non-commercial restriction)
- Add clean .gitignore and .env.docker.example
2026-04-20 22:48:06 +02:00

62 lines
1.3 KiB
TypeScript

// scripts/migrate-embeddings.ts
const { PrismaClient } = require('../prisma/client-generated')
const prisma = new PrismaClient({
datasources: {
db: {
url: process.env.DATABASE_URL || "file:../prisma/dev.db"
}
}
})
async function main() {
console.log("Fetching notes with embeddings...")
const notes = await prisma.note.findMany({
where: {
embedding: { not: null }
},
select: {
id: true,
embedding: true
}
})
console.log(`Found ${notes.length} notes with an embedding.`)
if (notes.length === 0) {
console.log("Nothing to migrate.")
return
}
let count = 0
for (const note of notes) {
if (!note.embedding) continue
await prisma.noteEmbedding.upsert({
where: { noteId: note.id },
create: {
noteId: note.id,
embedding: note.embedding
},
update: {
embedding: note.embedding
}
})
count++
if (count % 10 === 0) {
console.log(`Migrated ${count}/${notes.length}...`)
}
}
console.log(`✅ Successfully migrated ${count} note embeddings to the NoteEmbedding table.`)
}
main()
.catch((e) => {
console.error("Migration failed:", e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})