(tokens, i, params, filters)
| 3407 | // Check if dateAdded column exists |
| 3408 | const tableInfo = db.prepare("PRAGMA table_info(models)").all(); |
| 3409 | const hasDateAdded = tableInfo.some(col => col.name === 'dateAdded'); |
| 3410 | |
| 3411 | if (!hasDateAdded) { |
| 3412 | console.log('dateAdded column not found. Adding it...'); |
| 3413 | |
| 3414 | // Add the column |
| 3415 | db.prepare('ALTER TABLE models ADD COLUMN dateAdded DATETIME').run(); |
| 3416 | |
| 3417 | // For existing records, set dateAdded = modifiedDate as fallback, or current timestamp if modifiedDate is null |
| 3418 | db.prepare(` |
| 3419 | UPDATE models |
| 3420 | SET dateAdded = COALESCE(modifiedDate, datetime('now')) |
| 3421 | WHERE dateAdded IS NULL |
| 3422 | `).run(); |
| 3423 | |
| 3424 | console.log('dateAdded column added and existing records updated'); |
no test coverage detected