/**
 * FEAT-199: Adds email confirmation to user registration.
 * - confirmation_token: random string sent in confirmation email (null after confirmed)
 * - confirmed_at: timestamp when email was confirmed (null until confirmed)
 * - confirmed users can login; unconfirmed cannot.
 */

export const up = (pgm) => {
  pgm.addColumn('identity_users', {
    confirmation_token: {
      type: 'text',
      notNull: false,
      default: null,
    },
    confirmed_at: {
      type: 'timestamptz',
      notNull: false,
      default: null,
    },
    email_confirmed: {
      type: 'boolean',
      notNull: true,
      default: false,
    },
  });
  // FEAT-199: migrate existing users to confirmed (they already verified their email during signup)
  pgm.sql('UPDATE identity_users SET email_confirmed = true');
};

export const down = (pgm) => {
  pgm.dropColumns('identity_users', ['email_confirmed', 'confirmed_at', 'confirmation_token']);
};
