feat: add completion_date field to projects and update related functionalities in forms and queries
This commit is contained in:
29
migrate-add-completion-date.mjs
Normal file
29
migrate-add-completion-date.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
import db from "./src/lib/db.js";
|
||||
|
||||
export default function migrateAddCompletionDate() {
|
||||
try {
|
||||
// First, check if actual_completion_date exists and rename it to completion_date
|
||||
const columns = db.prepare("PRAGMA table_info(projects)").all();
|
||||
const hasActualCompletionDate = columns.some(col => col.name === 'actual_completion_date');
|
||||
const hasCompletionDate = columns.some(col => col.name === 'completion_date');
|
||||
|
||||
if (hasActualCompletionDate && !hasCompletionDate) {
|
||||
// Rename the column
|
||||
db.exec(`
|
||||
ALTER TABLE projects RENAME COLUMN actual_completion_date TO completion_date;
|
||||
`);
|
||||
console.log("Migration completed: Renamed actual_completion_date to completion_date");
|
||||
} else if (!hasActualCompletionDate && !hasCompletionDate) {
|
||||
// Add the column if it doesn't exist
|
||||
db.exec(`
|
||||
ALTER TABLE projects ADD COLUMN completion_date TEXT;
|
||||
`);
|
||||
console.log("Migration completed: Added completion_date column to projects table");
|
||||
} else if (hasCompletionDate) {
|
||||
console.log("Migration skipped: completion_date column already exists");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Migration failed:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user