feat: add edited_at column to notes and implement note update functionality with audit logging
This commit is contained in:
27
migrate-add-edited-at-to-notes.mjs
Normal file
27
migrate-add-edited-at-to-notes.mjs
Normal file
@@ -0,0 +1,27 @@
|
||||
import db from "./src/lib/db.js";
|
||||
|
||||
export default function migrateAddEditedAtToNotes() {
|
||||
try {
|
||||
// Check if edited_at column already exists
|
||||
const columns = db.prepare("PRAGMA table_info(notes)").all();
|
||||
const hasEditedAt = columns.some(col => col.name === 'edited_at');
|
||||
|
||||
if (!hasEditedAt) {
|
||||
// Add the edited_at column
|
||||
db.exec(`
|
||||
ALTER TABLE notes ADD COLUMN edited_at TEXT;
|
||||
`);
|
||||
console.log("Migration completed: Added edited_at column to notes table");
|
||||
} else {
|
||||
console.log("Migration skipped: edited_at column already exists");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Migration failed:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Run the migration if this file is executed directly
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
migrateAddEditedAtToNotes();
|
||||
}
|
||||
Reference in New Issue
Block a user