/**
 * Adds `updated_at` to the `notifications` table.
 *
 * The original 2026072100000030_notifications.js migration omitted this
 * column, but the controller's mark-read / read-all endpoints
 * (server/src/controllers/notifications.controller.js) write it.
 * Without the column, SQLite raises "no such column: updated_at" the
 * first time a user marks a notification read.
 *
 * SQLite ALTER TABLE ADD COLUMN doesn't accept non-constant DEFAULTs,
 * so the column is added nullable; the controller already supplies the
 * timestamp on every write so no backfill is needed.
 */
exports.up = async function (knex) {
  try {
    await knex.schema.raw(`ALTER TABLE notifications ADD COLUMN updated_at DATETIME`);
    console.log('[migrate:notifications-updated-at] notifications.updated_at added');
  } catch (e) {
    if (!/duplicate column/i.test(String(e.message || e))) {
      throw e;
    }
    console.log('[migrate:notifications-updated-at] notifications.updated_at already present');
  }
};

exports.down = async function (knex) {
  // SQLite doesn't support DROP COLUMN on older versions; the column is
  // harmless if the migration is rolled back, so leave it in place.
};