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
This commit is contained in:
Sepehr Ramezani
2026-04-20 22:48:06 +02:00
parent 402e88b788
commit e4d4e23dc7
3981 changed files with 407 additions and 530622 deletions

View File

@@ -0,0 +1,22 @@
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
const configs = await prisma.systemConfig.findMany()
console.log('--- System Config ---')
configs.forEach(c => {
if (c.key.startsWith('AI_') || c.key.startsWith('OLLAMA_')) {
console.log(`${c.key}: ${c.value}`)
}
})
}
main()
.catch(e => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})

View File

@@ -0,0 +1,76 @@
// Import directly from the generated client
const { PrismaClient } = require('./node_modules/@prisma/client')
const prisma = new PrismaClient()
async function checkLabels() {
try {
console.log('\n=== TOUS LES LABELS DANS LA TABLE Label ===')
const allLabels = await prisma.label.findMany({
select: { id: true, name: true, userId: true }
})
console.log(`Total: ${allLabels.length} labels`)
allLabels.forEach(l => {
console.log(` - ${l.name} (userId: ${l.userId}, id: ${l.id})`)
})
console.log('\n=== TOUS LES LABELS DANS LES NOTES (Note.labels) ===')
const allNotes = await prisma.note.findMany({
select: { id: true, labels: true, userId: true }
})
const labelsInNotes = new Set()
allNotes.forEach(note => {
if (note.labels) {
try {
const parsed = Array.isArray(note.labels) ? note.labels : []
if (Array.isArray(parsed)) {
parsed.forEach(l => labelsInNotes.add(l))
}
} catch (e) {}
}
})
console.log(`Total unique: ${labelsInNotes.size} labels`)
labelsInNotes.forEach(l => console.log(` - ${l}`))
console.log('\n=== LABELS ORPHELINS (dans Label table MAIS PAS dans les notes) ===')
const orphanLabels = []
allLabels.forEach(label => {
let found = false
labelsInNotes.forEach(noteLabel => {
if (noteLabel.toLowerCase() === label.name.toLowerCase()) {
found = true
}
})
if (!found) {
orphanLabels.push(label)
}
})
console.log(`Total orphans: ${orphanLabels.length}`)
orphanLabels.forEach(l => {
console.log(` - ${l.name} (userId: ${l.userId})`)
})
console.log('\n=== LABELS MANQUANTS (dans notes MAIS PAS dans Label table) ===')
const missingLabels = []
const existingLabelNames = new Set()
allLabels.forEach(l => existingLabelNames.add(l.name.toLowerCase()))
labelsInNotes.forEach(noteLabel => {
if (!existingLabelNames.has(noteLabel.toLowerCase())) {
missingLabels.push(noteLabel)
}
})
console.log(`Total missing: ${missingLabels.length}`)
missingLabels.forEach(l => console.log(` - ${l}`))
} catch (error) {
console.error('Error:', error)
} finally {
await prisma.$disconnect()
}
}
checkLabels()

View File

@@ -0,0 +1,35 @@
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
const users = await prisma.user.findMany({
include: {
aiSettings: true,
notes: {
take: 5,
orderBy: { updatedAt: 'desc' }
}
}
})
console.log('Total Users:', users.length)
for (const user of users) {
console.log(`User: ${user.email} (${user.id})`)
console.log(` AI Settings:`, user.aiSettings)
console.log(` Recent 5 Notes:`)
for (const note of user.notes) {
console.log(` ID: ${note.id}, Title: ${note.title}, Updated: ${note.updatedAt}, Dismissed: ${JSON.stringify(note)}`)
}
}
}
main()
.catch(e => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})

View File

@@ -0,0 +1,25 @@
import { prisma } from '../lib/prisma'
async function main() {
console.log('🔍 Checking users in database...')
console.log('Database URL used:', process.env.DATABASE_URL || "file:./dev.db")
const users = await prisma.user.findMany()
if (users.length === 0) {
console.log('❌ No users found in database!')
} else {
console.log(`✅ Found ${users.length} users:`)
console.table(users.map(u => ({
email: u.email,
role: u.role,
id: u.id,
hasPassword: !!u.password
})))
}
}
main()
.catch(e => console.error(e))
.finally(async () => await prisma.$disconnect())

View File

@@ -0,0 +1,41 @@
import { siteConfig } from '../config/site'
import { PrismaClient } from '@prisma/client'
async function main() {
console.log('🕵️‍♀️ Comparing Databases...')
// 1. Check Root DB
console.log('--- ROOT DB (./dev.db) ---')
const prismaRoot = new PrismaClient({
datasources: { db: { url: 'file:./dev.db' } }
})
try {
const countRoot = await prismaRoot.note.count()
console.log(`📦 Note Count: ${countRoot}`)
const usersRoot = await prismaRoot.user.count()
console.log(`👥 User Count: ${usersRoot}`)
} catch (e) {
console.log('❌ Failed to connect to Root DB', e)
} finally {
await prismaRoot.$disconnect()
}
// 2. Check Prisma Folder DB
console.log('\n--- PRISMA DB (./prisma/dev.db) ---')
const prismaPrisma = new PrismaClient({
datasources: { db: { url: 'file:./prisma/dev.db' } }
})
try {
const countPrisma = await prismaPrisma.note.count()
console.log(`📦 Note Count: ${countPrisma}`)
const usersPrisma = await prismaPrisma.user.count()
console.log(`👥 User Count: ${usersPrisma}`)
} catch (e) {
console.log('❌ Failed to connect to Prisma DB', e)
} finally {
await prismaPrisma.$disconnect()
}
}
main().catch(console.error)

View File

@@ -0,0 +1,31 @@
import { PrismaClient } from '../prisma/client-generated'
import bcrypt from 'bcryptjs'
const prisma = new PrismaClient()
async function main() {
const email = 'test@example.com'
const password = 'password123'
const hashedPassword = await bcrypt.hash(password, 10)
const user = await prisma.user.upsert({
where: { email },
update: { password: hashedPassword },
create: {
email,
name: 'Test User',
password: hashedPassword,
aiSettings: {
create: {
showRecentNotes: true // Ensure this is true!
}
}
}
})
console.log(`User created/updated: ${user.email}`)
}
main()
.catch(e => console.error(e))
.finally(async () => await prisma.$disconnect())

View File

@@ -0,0 +1,41 @@
import prisma from '../lib/prisma'
async function debugConfig() {
console.log('=== System Configuration Debug ===\n')
const configs = await prisma.systemConfig.findMany()
console.log(`Total configs in DB: ${configs.length}\n`)
// Group by category
const aiConfigs = configs.filter(c => c.key.startsWith('AI_'))
const ollamaConfigs = configs.filter(c => c.key.includes('OLLAMA'))
const openaiConfigs = configs.filter(c => c.key.includes('OPENAI'))
console.log('=== AI Provider Configs ===')
aiConfigs.forEach(c => {
console.log(`${c.key}: "${c.value}"`)
})
console.log('\n=== Ollama Configs ===')
ollamaConfigs.forEach(c => {
console.log(`${c.key}: "${c.value}"`)
})
console.log('\n=== OpenAI Configs ===')
openaiConfigs.forEach(c => {
console.log(`${c.key}: "${c.value}"`)
})
console.log('\n=== All Configs ===')
configs.forEach(c => {
console.log(`${c.key}: "${c.value}"`)
})
}
debugConfig()
.then(() => process.exit(0))
.catch((err) => {
console.error(err)
process.exit(1)
})

View File

@@ -0,0 +1,36 @@
import { getAllNotes } from '../app/actions/notes'
import { prisma } from '../lib/prisma'
async function main() {
console.log('🕵️‍♀️ Debugging getAllNotes...')
// 1. Get raw DB data for a sample note
const rawNote = await prisma.note.findFirst({
where: { size: { not: 'small' } }
})
if (rawNote) {
console.log('📊 Raw DB Note (should be large/medium):', {
id: rawNote.id,
size: rawNote.size
})
} else {
console.log('⚠️ No notes with size != small found in DB directly.')
}
// 2. Mock auth/session if needed (actions check session)
// Since we can't easily mock next-auth in this script environment without setup,
// we might need to rely on the direct DB check above or check if getAllNotes extracts userId safely.
// getAllNotes checks `auth()`. In this script context, `auth()` will arguably return null.
// So we can't easily run `getAllNotes` directly if it guards auth.
// Let's modify the plan: We will check the DB directly to confirm PERMANENCE.
// Then we will manually simulate `parseNote` logic.
const notes = await prisma.note.findMany({ take: 5 })
console.log('📋 Checking first 5 notes sizes in DB:')
notes.forEach(n => console.log(`- ${n.id}: ${n.size}`))
}
main().catch(console.error).finally(() => prisma.$disconnect())

View File

@@ -0,0 +1,60 @@
import { PrismaClient } from '../prisma/client-generated'
const prisma = new PrismaClient()
async function main() {
// 1. Get a user
const user = await prisma.user.findFirst()
if (!user) {
console.log('No user found in database.')
return
}
console.log(`Checking for User ID: ${user.id} (${user.email})`)
// 2. Simulate logic from app/actions/notes.ts
const sevenDaysAgo = new Date()
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7)
sevenDaysAgo.setHours(0, 0, 0, 0)
console.log(`Filtering for notes updated after: ${sevenDaysAgo.toISOString()}`)
// 3. Query Raw
const allNotes = await prisma.note.findMany({
where: { userId: user.id },
select: { id: true, title: true, contentUpdatedAt: true, updatedAt: true, dismissedFromRecent: true, isArchived: true }
})
console.log(`\nTotal Notes for User: ${allNotes.length}`)
// 4. Check "Recent" candidates
const recentCandidates = allNotes.filter(n => {
const noteDate = new Date(n.contentUpdatedAt)
return noteDate >= sevenDaysAgo
})
console.log(`Notes passing date filter: ${recentCandidates.length}`)
recentCandidates.forEach(n => {
console.log(` - [${n.title}] Updated: ${n.contentUpdatedAt.toISOString()} | Dismissed: ${n.dismissedFromRecent} | Archived: ${n.isArchived}`)
})
// 5. Check what the actual query returns
const actualQuery = await prisma.note.findMany({
where: {
userId: user.id,
contentUpdatedAt: { gte: sevenDaysAgo },
isArchived: false,
dismissedFromRecent: false
},
orderBy: { contentUpdatedAt: 'desc' },
take: 3
})
console.log(`\nActual Query Returns: ${actualQuery.length} notes`)
actualQuery.forEach(n => {
console.log(` -> [${n.title}]`)
})
}
main()
.catch(e => console.error(e))
.finally(async () => await prisma.$disconnect())

View File

@@ -0,0 +1,39 @@
import { PrismaClient } from '../prisma/client-generated'
const prisma = new PrismaClient()
async function main() {
console.log('Updating user settings to show recent notes...')
const updateResult = await prisma.userAISettings.updateMany({
data: {
showRecentNotes: true
}
})
console.log(`Updated ${updateResult.count} user settings.`)
// Verify and Create missing
const users = await prisma.user.findMany({
include: { aiSettings: true }
})
for (const u of users) {
if (!u.aiSettings) {
console.log(`User ${u.id} has no settings. Creating default...`)
await prisma.userAISettings.create({
data: {
userId: u.id,
showRecentNotes: true
}
})
console.log(`Created settings for ${u.id}`)
} else {
console.log(`User ${u.id}: showRecentNotes = ${u.aiSettings.showRecentNotes}`)
}
}
}
main()
.catch(e => console.error(e))
.finally(async () => await prisma.$disconnect())

View File

@@ -0,0 +1,24 @@
import { prisma } from '../lib/prisma'
async function main() {
console.log('👑 Granting ADMIN access to ALL users...')
try {
const result = await prisma.user.updateMany({
data: {
role: 'ADMIN'
}
})
console.log(`✅ Success! Updated ${result.count} users to ADMIN role.`)
} catch (error) {
console.error('❌ Error updating users:', error)
process.exit(1)
}
}
main()
.catch(e => console.error(e))
.finally(async () => await prisma.$disconnect())

View File

@@ -0,0 +1,61 @@
// 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()
})

View File

@@ -0,0 +1,388 @@
/**
* One-shot migration script: SQLite → PostgreSQL
*
* Reads data from the SQLite backup (prisma/dev.db) via better-sqlite3,
* connects to PostgreSQL via Prisma, and inserts all rows while converting
* JSON string fields to native objects (for Prisma Json type).
*
* Usage:
* DATABASE_URL="postgresql://keepnotes:keepnotes@localhost:5432/keepnotes" \
* npx tsx scripts/migrate-sqlite-to-postgres.ts
*
* Prerequisites:
* - PostgreSQL running and accessible via DATABASE_URL
* - prisma migrate deploy already run (schema exists)
* - better-sqlite3 still installed (temporary)
*/
import Database from 'better-sqlite3'
import { PrismaClient } from '../prisma/client-generated'
import * as path from 'path'
const SQLITE_PATH = path.join(__dirname, '..', 'prisma', 'dev.db')
// Parse a JSON string field, returning null if empty/invalid
function parseJsonField(raw: any): any {
if (raw === null || raw === undefined) return null
if (typeof raw !== 'string') return raw
if (raw === '' || raw === 'null') return null
try {
return JSON.parse(raw)
} catch {
return null
}
}
// Parse labels specifically — always return array or null
function parseLabels(raw: any): string[] | null {
const parsed = parseJsonField(raw)
if (Array.isArray(parsed)) return parsed
return null
}
// Parse embedding — always return number[] or null
function parseEmbedding(raw: any): number[] | null {
const parsed = parseJsonField(raw)
if (Array.isArray(parsed)) return parsed
return null
}
async function main() {
console.log('╔══════════════════════════════════════════════════════════╗')
console.log('║ SQLite → PostgreSQL Migration ║')
console.log('╚══════════════════════════════════════════════════════════╝')
console.log()
// 1. Open SQLite
let sqlite: Database.Database
try {
sqlite = new Database(SQLITE_PATH, { readonly: true })
console.log(`✓ SQLite opened: ${SQLITE_PATH}`)
} catch (e) {
console.error(`✗ Cannot open SQLite at ${SQLITE_PATH}: ${e}`)
process.exit(1)
}
// 2. Connect to PostgreSQL via Prisma
const prisma = new PrismaClient()
console.log(`✓ PostgreSQL connected via Prisma`)
console.log()
// Helper to read all rows from SQLite
function allRows(sql: string): any[] {
return sqlite.prepare(sql).all() as any[]
}
let totalInserted = 0
// ── User ──────────────────────────────────────────────────
console.log('Migrating User...')
const users = allRows('SELECT * FROM User')
for (const u of users) {
await prisma.user.upsert({
where: { id: u.id },
update: {},
create: {
id: u.id,
name: u.name,
email: u.email,
emailVerified: u.emailVerified ? new Date(u.emailVerified) : null,
password: u.password,
role: u.role || 'USER',
image: u.image,
theme: u.theme || 'light',
resetToken: u.resetToken,
resetTokenExpiry: u.resetTokenExpiry ? new Date(u.resetTokenExpiry) : null,
createdAt: u.createdAt ? new Date(u.createdAt) : new Date(),
updatedAt: u.updatedAt ? new Date(u.updatedAt) : new Date(),
}
})
}
console.log(`${users.length} users`)
totalInserted += users.length
// ── Account ───────────────────────────────────────────────
console.log('Migrating Account...')
const accounts = allRows('SELECT * FROM Account')
for (const a of accounts) {
await prisma.account.create({
data: {
userId: a.userId,
type: a.type,
provider: a.provider,
providerAccountId: a.providerAccountId,
refresh_token: a.refresh_token,
access_token: a.access_token,
expires_at: a.expires_at,
token_type: a.token_type,
scope: a.scope,
id_token: a.id_token,
session_state: a.session_state,
createdAt: a.createdAt ? new Date(a.createdAt) : new Date(),
updatedAt: a.updatedAt ? new Date(a.updatedAt) : new Date(),
}
}).catch(() => {}) // skip duplicates
}
console.log(`${accounts.length} accounts`)
totalInserted += accounts.length
// ── Session ───────────────────────────────────────────────
console.log('Migrating Session...')
const sessions = allRows('SELECT * FROM Session')
for (const s of sessions) {
await prisma.session.create({
data: {
sessionToken: s.sessionToken,
userId: s.userId,
expires: s.expires ? new Date(s.expires) : new Date(),
createdAt: s.createdAt ? new Date(s.createdAt) : new Date(),
updatedAt: s.updatedAt ? new Date(s.updatedAt) : new Date(),
}
}).catch(() => {})
}
console.log(`${sessions.length} sessions`)
totalInserted += sessions.length
// ── Notebook ──────────────────────────────────────────────
console.log('Migrating Notebook...')
const notebooks = allRows('SELECT * FROM Notebook')
for (const nb of notebooks) {
await prisma.notebook.create({
data: {
id: nb.id,
name: nb.name,
icon: nb.icon,
color: nb.color,
order: nb.order ?? 0,
userId: nb.userId,
createdAt: nb.createdAt ? new Date(nb.createdAt) : new Date(),
updatedAt: nb.updatedAt ? new Date(nb.updatedAt) : new Date(),
}
}).catch(() => {})
}
console.log(`${notebooks.length} notebooks`)
totalInserted += notebooks.length
// ── Label ─────────────────────────────────────────────────
console.log('Migrating Label...')
const labels = allRows('SELECT * FROM Label')
for (const l of labels) {
await prisma.label.create({
data: {
id: l.id,
name: l.name,
color: l.color || 'gray',
notebookId: l.notebookId,
userId: l.userId,
createdAt: l.createdAt ? new Date(l.createdAt) : new Date(),
updatedAt: l.updatedAt ? new Date(l.updatedAt) : new Date(),
}
}).catch(() => {})
}
console.log(`${labels.length} labels`)
totalInserted += labels.length
// ── Note ──────────────────────────────────────────────────
console.log('Migrating Note...')
const notes = allRows('SELECT * FROM Note')
let noteCount = 0
for (const n of notes) {
await prisma.note.create({
data: {
id: n.id,
title: n.title,
content: n.content || '',
color: n.color || 'default',
isPinned: n.isPinned === 1 || n.isPinned === true,
isArchived: n.isArchived === 1 || n.isArchived === true,
type: n.type || 'text',
dismissedFromRecent: n.dismissedFromRecent === 1 || n.dismissedFromRecent === true,
checkItems: parseJsonField(n.checkItems),
labels: parseLabels(n.labels),
images: parseJsonField(n.images),
links: parseJsonField(n.links),
reminder: n.reminder ? new Date(n.reminder) : null,
isReminderDone: n.isReminderDone === 1 || n.isReminderDone === true,
reminderRecurrence: n.reminderRecurrence,
reminderLocation: n.reminderLocation,
isMarkdown: n.isMarkdown === 1 || n.isMarkdown === true,
size: n.size || 'small',
embedding: parseEmbedding(n.embedding),
sharedWith: parseJsonField(n.sharedWith),
userId: n.userId,
order: n.order ?? 0,
notebookId: n.notebookId,
createdAt: n.createdAt ? new Date(n.createdAt) : new Date(),
updatedAt: n.updatedAt ? new Date(n.updatedAt) : new Date(),
contentUpdatedAt: n.contentUpdatedAt ? new Date(n.contentUpdatedAt) : new Date(),
autoGenerated: n.autoGenerated === 1 ? true : n.autoGenerated === 0 ? false : null,
aiProvider: n.aiProvider,
aiConfidence: n.aiConfidence,
language: n.language,
languageConfidence: n.languageConfidence,
lastAiAnalysis: n.lastAiAnalysis ? new Date(n.lastAiAnalysis) : null,
}
}).catch((e) => {
console.error(` Failed note ${n.id}: ${e.message}`)
})
noteCount++
}
console.log(`${noteCount} notes`)
totalInserted += noteCount
// ── NoteShare ─────────────────────────────────────────────
console.log('Migrating NoteShare...')
const noteShares = allRows('SELECT * FROM NoteShare')
for (const ns of noteShares) {
await prisma.noteShare.create({
data: {
id: ns.id,
noteId: ns.noteId,
userId: ns.userId,
sharedBy: ns.sharedBy,
status: ns.status || 'pending',
permission: ns.permission || 'view',
notifiedAt: ns.notifiedAt ? new Date(ns.notifiedAt) : null,
respondedAt: ns.respondedAt ? new Date(ns.respondedAt) : null,
createdAt: ns.createdAt ? new Date(ns.createdAt) : new Date(),
updatedAt: ns.updatedAt ? new Date(ns.updatedAt) : new Date(),
}
}).catch(() => {})
}
console.log(`${noteShares.length} note shares`)
totalInserted += noteShares.length
// ── AiFeedback ────────────────────────────────────────────
console.log('Migrating AiFeedback...')
const aiFeedbacks = allRows('SELECT * FROM AiFeedback')
for (const af of aiFeedbacks) {
await prisma.aiFeedback.create({
data: {
id: af.id,
noteId: af.noteId,
userId: af.userId,
feedbackType: af.feedbackType,
feature: af.feature,
originalContent: af.originalContent || '',
correctedContent: af.correctedContent,
metadata: parseJsonField(af.metadata),
createdAt: af.createdAt ? new Date(af.createdAt) : new Date(),
}
}).catch(() => {})
}
console.log(`${aiFeedbacks.length} ai feedbacks`)
totalInserted += aiFeedbacks.length
// ── MemoryEchoInsight ─────────────────────────────────────
console.log('Migrating MemoryEchoInsight...')
const insights = allRows('SELECT * FROM MemoryEchoInsight')
for (const mi of insights) {
await prisma.memoryEchoInsight.create({
data: {
id: mi.id,
userId: mi.userId,
note1Id: mi.note1Id,
note2Id: mi.note2Id,
similarityScore: mi.similarityScore ?? 0,
insight: mi.insight || '',
insightDate: mi.insightDate ? new Date(mi.insightDate) : new Date(),
viewed: mi.viewed === 1 || mi.viewed === true,
feedback: mi.feedback,
dismissed: mi.dismissed === 1 || mi.dismissed === true,
}
}).catch(() => {})
}
console.log(`${insights.length} memory echo insights`)
totalInserted += insights.length
// ── UserAISettings ────────────────────────────────────────
console.log('Migrating UserAISettings...')
const aiSettings = allRows('SELECT * FROM UserAISettings')
for (const s of aiSettings) {
await prisma.userAISettings.create({
data: {
userId: s.userId,
titleSuggestions: s.titleSuggestions === 1 || s.titleSuggestions === true,
semanticSearch: s.semanticSearch === 1 || s.semanticSearch === true,
paragraphRefactor: s.paragraphRefactor === 1 || s.paragraphRefactor === true,
memoryEcho: s.memoryEcho === 1 || s.memoryEcho === true,
memoryEchoFrequency: s.memoryEchoFrequency || 'daily',
aiProvider: s.aiProvider || 'auto',
preferredLanguage: s.preferredLanguage || 'auto',
fontSize: s.fontSize || 'medium',
demoMode: s.demoMode === 1 || s.demoMode === true,
showRecentNotes: s.showRecentNotes === 1 || s.showRecentNotes === true,
notesViewMode: s.notesViewMode || 'masonry',
emailNotifications: s.emailNotifications === 1 || s.emailNotifications === true,
desktopNotifications: s.desktopNotifications === 1 || s.desktopNotifications === true,
anonymousAnalytics: s.anonymousAnalytics === 1 || s.anonymousAnalytics === true,
}
}).catch(() => {})
}
console.log(`${aiSettings.length} user AI settings`)
totalInserted += aiSettings.length
// ── SystemConfig ──────────────────────────────────────────
console.log('Migrating SystemConfig...')
const configs = allRows('SELECT * FROM SystemConfig')
for (const c of configs) {
await prisma.systemConfig.create({
data: {
key: c.key,
value: c.value,
}
}).catch(() => {})
}
console.log(`${configs.length} system configs`)
totalInserted += configs.length
// ── _LabelToNote (many-to-many relations) ─────────────────
console.log('Migrating Label-Note relations...')
let relationCount = 0
try {
const relations = allRows('SELECT * FROM _LabelToNote')
for (const r of relations) {
await prisma.note.update({
where: { id: r.B },
data: {
labelRelations: { connect: { id: r.A } }
}
}).catch(() => {})
relationCount++
}
} catch {
// Table may not exist in older SQLite databases
console.log(' → _LabelToNote table not found, skipping')
}
console.log(`${relationCount} label-note relations`)
totalInserted += relationCount
// ── VerificationToken ─────────────────────────────────────
console.log('Migrating VerificationToken...')
const tokens = allRows('SELECT * FROM VerificationToken')
for (const t of tokens) {
await prisma.verificationToken.create({
data: {
identifier: t.identifier,
token: t.token,
expires: t.expires ? new Date(t.expires) : new Date(),
}
}).catch(() => {})
}
console.log(`${tokens.length} verification tokens`)
totalInserted += tokens.length
// Cleanup
sqlite.close()
await prisma.$disconnect()
console.log()
console.log('╔══════════════════════════════════════════════════════════╗')
console.log(`║ Migration complete: ${totalInserted} total rows inserted ║`)
console.log('╚══════════════════════════════════════════════════════════╝')
}
main().catch((e) => {
console.error('Migration failed:', e)
process.exit(1)
})

View File

@@ -0,0 +1,35 @@
const { PrismaClient } = require('../prisma/client-generated');
const prisma = new PrismaClient();
async function promoteAdmin() {
const email = process.argv[2];
try {
let user;
if (email) {
user = await prisma.user.findUnique({ where: { email } });
} else {
console.log("Aucun email fourni, promotion du premier utilisateur trouvé...");
user = await prisma.user.findFirst();
}
if (!user) {
console.error("Aucun utilisateur trouvé.");
return;
}
await prisma.user.update({
where: { id: user.id },
data: { role: 'ADMIN' }
});
console.log(`Succès : L'utilisateur ${user.email} (${user.name}) est maintenant ADMIN.`);
} catch (e) {
console.error("Erreur :", e);
} finally {
await prisma.$disconnect();
}
}
promoteAdmin();

View File

@@ -0,0 +1,67 @@
import { PrismaClient } from '../prisma/client-generated'
import { getAIProvider } from '../lib/ai/factory'
import { getSystemConfig } from '../lib/config'
const prisma = new PrismaClient()
async function regenerateAllEmbeddings() {
console.log('🔄 Starting embedding regeneration...\n')
// Get all notes
const notes = await prisma.note.findMany({
select: {
id: true,
title: true,
content: true
}
})
console.log(`📝 Found ${notes.length} notes to process\n`)
// Get AI provider
const config = await getSystemConfig()
const provider = getAIProvider(config)
console.log(`🤖 Using AI provider...`)
let successCount = 0
let errorCount = 0
for (const note of notes) {
try {
const title = note.title || '(no title)'
process.stdout.write(`\r⏳ Processing ${successCount + 1}/${notes.length}: ${title.substring(0, 40)}...`)
// Generate new embedding
const embedding = await provider.getEmbeddings(note.content)
if (embedding) {
// Update note with new embedding
await prisma.note.update({
where: { id: note.id },
data: {
embedding
}
})
successCount++
} else {
errorCount++
console.log(`\n❌ Failed: ${title} (no embedding generated)`)
}
} catch (error) {
errorCount++
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
console.log(`\n❌ Error: ${note.title || '(no title)'} - ${errorMessage}`)
}
}
console.log(`\n\n📊 Summary:`)
console.log(` ✅ Success: ${successCount}/${notes.length}`)
console.log(` ❌ Errors: ${errorCount}/${notes.length}`)
console.log('\n✨ Embeddings regenerated successfully!')
await prisma.$disconnect()
}
regenerateAllEmbeddings().catch(console.error)

View File

@@ -0,0 +1,36 @@
import { prisma } from '../lib/prisma'
import bcrypt from 'bcryptjs'
async function main() {
const email = 'test@example.com'
const newPassword = 'password123'
console.log(`Resetting password for ${email}...`)
const hashedPassword = await bcrypt.hash(newPassword, 10)
try {
const user = await prisma.user.update({
where: { email },
data: {
password: hashedPassword,
resetToken: null,
resetTokenExpiry: null
},
})
console.log(`✅ Password successfully reset for ${user.email}`)
} catch (error) {
console.error('❌ Error resetting password:', error)
process.exit(1)
}
}
main()
.catch(e => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})

View File

@@ -0,0 +1,145 @@
/**
* Script DIRECT de reset de mot de passe
*
* POURQUOI CE SCRIPT ?
* -----------------
* - Le compte `test@example.com` N'EXISTE PAS (vous avez raison !)
* - L'envoi d'email nécessite une configuration SMTP complexe
* - VOUS VOULEZ UNE SOLUTION DIRECTE, SANS PERDRE DE TEMPS
*
* CE QUE FAIT CE SCRIPT :
* -------------------
* - Réinitialise DIRECTEMENT le mot de passe d'un compte existant
* - Sans avoir besoin d'email
* - Sans avoir besoin d'interface graphique
*
* COMMENT UTILISER :
* ---------------
* 1. Ouvrez un terminal dans le dossier memento-note
* 2. Exécutez: node scripts/reset-password.js
* 3. Quand demandé, entrez l'email du compte à réinitialiser
* 4. Entrez le nouveau mot de passe (2 fois pour confirmation)
* 5. FINI ! Connectez-vous avec le nouveau mot de passe
*/
const readline = require('readline');
const bcrypt = require('bcryptjs');
const prisma = require('../lib/prisma').default;
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log('╔══════════════════════════════════════════════════════════════════╗');
console.log('║ RESET DE MOT DE PASSE DIRECT ║');
console.log('║ ║');
console.log('║ ⚠️ ATTENTION : Utilisez seulement pour VOTRE propre compte ! ║');
console.log('║ ║');
console.log('╚══════════════════════════════════════════════════════════════════════╝');
console.log('');
rl.question('Entrez l\'EMAIL du compte à réinitialiser : ', async (email) => {
if (!email || !email.includes('@')) {
console.log('❌ Erreur : Email invalide !');
rl.close();
process.exit(1);
}
email = email.toLowerCase().trim();
console.log(`🔍 Recherche du compte : ${email}...`);
try {
const user = await prisma.user.findUnique({
where: { email: email }
});
if (!user) {
console.log('');
console.log('❌ ERREUR : AUCUN compte trouvé avec cet email !');
console.log('');
console.log('📋 COMPTES DISPONIBLES (si existants) :');
console.log('─────────────────────────────────────────');
// Afficher tous les utilisateurs de la base de données
const allUsers = await prisma.user.findMany({
select: { email: true, name: true, role: true, createdAt: true },
orderBy: { createdAt: 'desc' }
});
if (allUsers.length > 0) {
console.log('');
allUsers.forEach((u, index) => {
console.log(`${index + 1}. 📧 Email: ${u.email}`);
console.log(` 👤 Nom: ${u.name || 'N/A'}`);
console.log(` 🏷️ Rôle: ${u.role}`);
console.log(` 📅 Créé: ${u.createdAt.toLocaleString('fr-FR')}`);
console.log('');
});
} else {
console.log(' (Aucun compte dans la base de données)');
}
console.log('─────────────────────────────────────────');
console.log('');
rl.close();
process.exit(1);
}
console.log(`✅ Compte trouvé : ${user.email} (${user.name})`);
console.log('');
rl.question('Entrez le NOUVEAU mot de passe (minimum 6 caractères) : ', async (newPassword) => {
if (!newPassword || newPassword.length < 6) {
console.log('❌ Erreur : Le mot de passe doit avoir au moins 6 caractères !');
rl.close();
process.exit(1);
}
rl.question('Confirmez le nouveau mot de passe : ', async (confirmPassword) => {
if (newPassword !== confirmPassword) {
console.log('❌ Erreur : Les mots de passe ne correspondent pas !');
rl.close();
process.exit(1);
}
console.log('');
console.log('🔄 Réinitialisation du mot de passe en cours...');
const hashedPassword = await bcrypt.hash(newPassword, 10);
await prisma.user.update({
where: { id: user.id },
data: {
password: hashedPassword,
resetToken: null,
resetTokenExpiry: null
}
});
console.log('✅ SUCCÈS ! Le mot de passe a été réinitialisé !');
console.log('');
console.log('═══════════════════════════════════════════════════════════════════════');
console.log('🎉 VOUS POUVEZ MAINTENANT VOUS CONNECTER !');
console.log('═════════════════════════════════════════════════════════════════════');
console.log('');
console.log('📱 URL de connexion : http://localhost:3000/login');
console.log('📧 Email :', email);
console.log('🔑 Mot de passe :', newPassword);
console.log('');
console.log('⏩ Copiez ces informations et connectez-vous !');
console.log('');
rl.close();
process.exit(0);
});
});
} catch (error) {
console.log('');
console.log('❌ ERREUR lors de la réinitialisation :');
console.error(error);
rl.close();
process.exit(1);
}
});

View File

@@ -0,0 +1,22 @@
import { PrismaClient } from '@prisma/client'
import bcrypt from 'bcryptjs'
const prisma = new PrismaClient()
async function main() {
const hashedPassword = await bcrypt.hash('password123', 10)
const user = await prisma.user.upsert({
where: { email: 'test@example.com' },
update: {},
create: {
email: 'test@example.com',
name: 'Test User',
password: hashedPassword,
},
})
console.log('User created:', user)
}
main()
.catch(e => console.error(e))
.finally(async () => await prisma.$disconnect())

View File

@@ -0,0 +1,48 @@
import prisma from '../lib/prisma'
/**
* Setup OpenAI as default AI provider in database
* Run this to ensure OpenAI is properly configured
*/
async function setupOpenAI() {
console.log('🔧 Setting up OpenAI as default AI provider...\n')
const configs = [
{ key: 'AI_PROVIDER_TAGS', value: 'openai' },
{ key: 'AI_PROVIDER_EMBEDDING', value: 'openai' },
{ key: 'AI_MODEL_TAGS', value: 'gpt-4o-mini' },
{ key: 'AI_MODEL_EMBEDDING', value: 'text-embedding-3-small' },
]
try {
for (const config of configs) {
await prisma.systemConfig.upsert({
where: { key: config.key },
update: { value: config.value },
create: { key: config.key, value: config.value }
})
console.log(`✅ Set ${config.key} = ${config.value}`)
}
console.log('\n✨ OpenAI configuration complete!')
console.log('\nNext steps:')
console.log('1. Add your OPENAI_API_KEY in admin settings: http://localhost:3000/admin/settings')
console.log('2. Or add it to .env.docker: OPENAI_API_KEY=sk-...')
console.log('3. Restart the application')
// Verify
const verify = await prisma.systemConfig.findMany({
where: { key: { in: configs.map(c => c.key) } }
})
console.log('\n✅ Verification:')
verify.forEach(c => console.log(` ${c.key}: ${c.value}`))
} catch (error) {
console.error('❌ Error:', error)
process.exit(1)
}
}
setupOpenAI()
.then(() => process.exit(0))
.catch(() => process.exit(1))

View File

@@ -0,0 +1,48 @@
// scripts/switch-db.js
const fs = require('fs')
const path = require('path')
const envPath = path.join(__dirname, '..', '.env')
const schemaPath = path.join(__dirname, '..', 'prisma', 'schema.prisma')
const target = process.argv[2]
if (!['sqlite', 'postgresql'].includes(target)) {
console.error("Usage: node scripts/switch-db.js [sqlite|postgresql]")
process.exit(1)
}
// 1. Update schema.prisma
let schemaContent = fs.readFileSync(schemaPath, 'utf8')
// Find the datasource db block and replace the provider
schemaContent = schemaContent.replace(
/datasource db \{\s*provider\s*=\s*"[^"]+"/g,
`datasource db {\n provider = "${target}"`
)
fs.writeFileSync(schemaPath, schemaContent)
// 2. Update .env
let envContent = fs.existsSync(envPath) ? fs.readFileSync(envPath, 'utf8') : ''
const sqliteUrl = 'file:./dev.db'
const pgUrl = 'postgresql://postgres:postgres@localhost:5432/keep_notes?schema=public'
// Update or append DATABASE_URL
if (target === 'sqlite') {
if (envContent.match(/^DATABASE_URL=.*$/m)) {
envContent = envContent.replace(/^DATABASE_URL=.*$/m, `DATABASE_URL="${sqliteUrl}"`)
} else {
envContent += `\nDATABASE_URL="${sqliteUrl}"`
}
} else {
if (envContent.match(/^DATABASE_URL=.*$/m)) {
envContent = envContent.replace(/^DATABASE_URL=.*$/m, `DATABASE_URL="${pgUrl}"`)
} else {
envContent += `\nDATABASE_URL="${pgUrl}"`
}
}
fs.writeFileSync(envPath, envContent)
console.log(`✅ Successfully switched database provider to ${target}`)
console.log('You should now run:')
console.log(' npx prisma generate')
console.log(' npx prisma db push')

View File

@@ -0,0 +1,63 @@
import { prisma } from '../lib/prisma'
// Copy of parseNote from app/actions/notes.ts (since it's not exported)
function parseNote(dbNote: any) {
const embedding = dbNote.embedding ? JSON.parse(dbNote.embedding) : null
if (embedding && Array.isArray(embedding)) {
// Simplified validation check for test
if (embedding.length !== 1536 && embedding.length !== 768 && embedding.length !== 384) {
return {
...dbNote,
checkItems: dbNote.checkItems ? JSON.parse(dbNote.checkItems) : null,
labels: dbNote.labels ? JSON.parse(dbNote.labels) : null,
images: dbNote.images ? JSON.parse(dbNote.images) : null,
links: dbNote.links ? JSON.parse(dbNote.links) : null,
embedding: null,
sharedWith: dbNote.sharedWith ? JSON.parse(dbNote.sharedWith) : [],
size: dbNote.size || 'small',
}
}
}
return {
...dbNote,
checkItems: dbNote.checkItems ? JSON.parse(dbNote.checkItems) : null,
labels: dbNote.labels ? JSON.parse(dbNote.labels) : null,
images: dbNote.images ? JSON.parse(dbNote.images) : null,
links: dbNote.links ? JSON.parse(dbNote.links) : null,
embedding,
sharedWith: dbNote.sharedWith ? JSON.parse(dbNote.sharedWith) : [],
size: dbNote.size || 'small',
}
}
async function main() {
console.log('🧪 Testing parseNote logic...')
// 1. Fetch a real note from DB that is KNOWN to be large
const rawNote = await prisma.note.findFirst({
where: { size: 'large' }
})
if (!rawNote) {
console.error('❌ No large note found in DB. Create one first.')
return
}
console.log('📊 Raw Note from DB:', { id: rawNote.id, size: rawNote.size })
// 2. Pass it through parseNote
const parsed = parseNote(rawNote)
console.log('🔄 Parsed Note:', { id: parsed.id, size: parsed.size })
if (parsed.size === 'large') {
console.log('✅ parseNote preserves size correctly.')
} else {
console.error('❌ parseNote returned wrong size:', parsed.size)
}
}
main().catch(console.error).finally(() => prisma.$disconnect())

View File

@@ -0,0 +1,56 @@
import { prisma } from '../lib/prisma'
import { updateSize } from '../app/actions/notes'
async function main() {
console.log('🧪 Starting Note Size Persistence Verification...')
// 1. Create a test note
const note = await prisma.note.create({
data: {
content: 'Size Test Note',
userId: (await prisma.user.findFirst())?.id || '',
size: 'small', // Start small
}
})
console.log(`📝 Created test note (${note.id}) with size: ${note.size}`)
if (!note.userId) {
console.error('❌ No user found to create note. Aborting.')
return
}
try {
// 2. Update size to LARGE
console.log('🔄 Updating size to LARGE...')
// We mock the session for the action or call prisma directly if action fails (actions usually need auth context)
// Since we're running as script, we'll use prisma update directly to simulate what the action does at DB level
// OR we can try to invoke the action if we can mock auth.
// Let's test the DB interaction first which is the critical "persistence" part.
await prisma.note.update({
where: { id: note.id },
data: { size: 'large' }
})
// 3. Fetch back
const updatedNote = await prisma.note.findUnique({ where: { id: note.id } })
console.log(`🔍 Fetched note after update. Size is: ${updatedNote?.size}`)
if (updatedNote?.size === 'large') {
console.log('✅ BACKEND PERSISTENCE: PASSED')
} else {
console.error('❌ BACKEND PERSISTENCE: FAILED (Size reverted or did not update)')
}
} catch (error) {
console.error('❌ Error during test:', error)
} finally {
// Cleanup
await prisma.note.delete({ where: { id: note.id } })
console.log('🧹 Cleaned up test note')
await prisma.$disconnect()
}
}
main().catch(console.error)