mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
import { run } from "./db.js";
|
|
|
|
async function updateDatabaseSchema() {
|
|
try {
|
|
console.log("Checking and updating database schema...");
|
|
|
|
// Check if last_updated column exists in teams table
|
|
try {
|
|
// Add last_updated column to teams table if it doesn't exist
|
|
// SQLite syntax for adding columns if they don't exist
|
|
await run(`
|
|
ALTER TABLE teams ADD COLUMN last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
|
`);
|
|
console.log("Added last_updated column to teams table");
|
|
} catch (error) {
|
|
// If error contains "duplicate column name" then the column already exists
|
|
if (!error.message.includes("duplicate column name")) {
|
|
throw error; // Re-throw if it's a different error
|
|
}
|
|
console.log("last_updated column already exists in teams table");
|
|
}
|
|
|
|
console.log("Database schema update completed successfully");
|
|
} catch (error) {
|
|
console.error("Database schema update error:", error);
|
|
}
|
|
}
|
|
|
|
// Run the update
|
|
updateDatabaseSchema();
|
|
|
|
// Export for potential use in other modules
|
|
export default updateDatabaseSchema;
|