feat: Add user tracking to project tasks and notes
- Implemented user tracking columns in project_tasks and notes tables. - Added created_by and assigned_to fields to project_tasks. - Introduced created_by field and is_system flag in notes. - Updated API endpoints to handle user tracking during task and note creation. - Enhanced database initialization to include new columns and indexes. - Created utility functions to fetch users for task assignment. - Updated front-end components to display user information for tasks and notes. - Added tests for project-tasks API endpoints to verify functionality.
This commit is contained in:
60
fix-notes-columns.mjs
Normal file
60
fix-notes-columns.mjs
Normal file
@@ -0,0 +1,60 @@
|
||||
import Database from "better-sqlite3";
|
||||
|
||||
const db = new Database("./data/database.sqlite");
|
||||
|
||||
console.log("Adding user tracking columns to notes table...\n");
|
||||
|
||||
try {
|
||||
console.log("Adding created_by column...");
|
||||
db.exec(`ALTER TABLE notes ADD COLUMN created_by TEXT;`);
|
||||
console.log("✓ created_by column added");
|
||||
} catch (e) {
|
||||
console.log("created_by column already exists or error:", e.message);
|
||||
}
|
||||
|
||||
try {
|
||||
console.log("Adding is_system column...");
|
||||
db.exec(`ALTER TABLE notes ADD COLUMN is_system INTEGER DEFAULT 0;`);
|
||||
console.log("✓ is_system column added");
|
||||
} catch (e) {
|
||||
console.log("is_system column already exists or error:", e.message);
|
||||
}
|
||||
|
||||
console.log("\nVerifying columns were added...");
|
||||
const schema = db.prepare("PRAGMA table_info(notes)").all();
|
||||
const hasCreatedBy = schema.some((col) => col.name === "created_by");
|
||||
const hasIsSystem = schema.some((col) => col.name === "is_system");
|
||||
|
||||
console.log("created_by exists:", hasCreatedBy);
|
||||
console.log("is_system exists:", hasIsSystem);
|
||||
|
||||
if (hasCreatedBy && hasIsSystem) {
|
||||
console.log("\n✅ All columns are now present!");
|
||||
|
||||
// Test a manual insert
|
||||
console.log("\nTesting manual note insert...");
|
||||
try {
|
||||
const result = db
|
||||
.prepare(
|
||||
`
|
||||
INSERT INTO notes (project_id, note, created_by, is_system, note_date)
|
||||
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
`
|
||||
)
|
||||
.run(1, "Test note with user tracking", "test-user-id", 0);
|
||||
|
||||
console.log("Insert successful, ID:", result.lastInsertRowid);
|
||||
|
||||
// Clean up
|
||||
db.prepare("DELETE FROM notes WHERE note_id = ?").run(
|
||||
result.lastInsertRowid
|
||||
);
|
||||
console.log("Test record cleaned up");
|
||||
} catch (error) {
|
||||
console.error("Insert failed:", error.message);
|
||||
}
|
||||
} else {
|
||||
console.log("\n❌ Some columns are still missing");
|
||||
}
|
||||
|
||||
db.close();
|
||||
Reference in New Issue
Block a user