feat: Add migration script to add 'initial' column to users table
This commit is contained in:
43
migrate-add-initial-column.mjs
Normal file
43
migrate-add-initial-column.mjs
Normal file
@@ -0,0 +1,43 @@
|
||||
import Database from "better-sqlite3";
|
||||
|
||||
// Migration script to add 'initial' column to users table
|
||||
// Run this on your live server to apply the database changes
|
||||
|
||||
const dbPath = process.argv[2] || "./data/database.sqlite"; // Allow custom path via command line
|
||||
|
||||
console.log(`Applying migration to database: ${dbPath}`);
|
||||
|
||||
try {
|
||||
const db = new Database(dbPath);
|
||||
|
||||
// Check if initial column already exists
|
||||
const schema = db.prepare("PRAGMA table_info(users)").all();
|
||||
const hasInitialColumn = schema.some(column => column.name === 'initial');
|
||||
|
||||
if (hasInitialColumn) {
|
||||
console.log("✅ Initial column already exists in users table");
|
||||
} else {
|
||||
// Add the initial column
|
||||
db.prepare("ALTER TABLE users ADD COLUMN initial TEXT").run();
|
||||
console.log("✅ Added 'initial' column to users table");
|
||||
}
|
||||
|
||||
// Verify the column was added
|
||||
const updatedSchema = db.prepare("PRAGMA table_info(users)").all();
|
||||
const initialColumn = updatedSchema.find(column => column.name === 'initial');
|
||||
|
||||
if (initialColumn) {
|
||||
console.log("✅ Migration completed successfully");
|
||||
console.log(`Column details: ${JSON.stringify(initialColumn, null, 2)}`);
|
||||
} else {
|
||||
console.error("❌ Migration failed - initial column not found");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
db.close();
|
||||
console.log("Database connection closed");
|
||||
|
||||
} catch (error) {
|
||||
console.error("❌ Migration failed:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user