/* eslint-disable */
module.exports = {
  async up(queryInterface, Sequelize) {
    // Für bereits existierende Installationen: Spalte sicherstellen + Backfill
    await queryInterface.sequelize.query(`
      ALTER TABLE falukant_type.reputation_action
      ADD COLUMN IF NOT EXISTS decay_window_days integer;
    `);
    await queryInterface.sequelize.query(`
      UPDATE falukant_type.reputation_action
      SET decay_window_days = 7
      WHERE decay_window_days IS NULL;
    `);
    await queryInterface.sequelize.query(`
      ALTER TABLE falukant_type.reputation_action
      ALTER COLUMN decay_window_days SET DEFAULT 7;
    `);
    await queryInterface.sequelize.query(`
      ALTER TABLE falukant_type.reputation_action
      ALTER COLUMN decay_window_days SET NOT NULL;
    `);
    await queryInterface.sequelize.query(`
      ALTER TABLE falukant_type.reputation_action
      DROP CONSTRAINT IF EXISTS reputation_action_decay_window_days_chk;
    `);
    await queryInterface.sequelize.query(`
      ALTER TABLE falukant_type.reputation_action
      ADD CONSTRAINT reputation_action_decay_window_days_chk
      CHECK (decay_window_days >= 1 AND decay_window_days <= 365);
    `);
  },

  async down(queryInterface, Sequelize) {
    // optional: wieder entfernen
    await queryInterface.sequelize.query(`
      ALTER TABLE falukant_type.reputation_action
      DROP CONSTRAINT IF EXISTS reputation_action_decay_window_days_chk;
    `);
    await queryInterface.sequelize.query(`
      ALTER TABLE falukant_type.reputation_action
      DROP COLUMN IF EXISTS decay_window_days;
    `);
  },
};


