-- +goose Up
ALTER TABLE permissions
  ADD COLUMN requires_pin TINYINT(1) NOT NULL DEFAULT 0 AFTER description;

UPDATE permissions
SET requires_pin = 1
WHERE (updated_by IS NULL OR LENGTH(updated_by) = 0)
  AND `key` IN (
    'user.create',
    'user.update',
    'user.delete',
    'role.create',
    'role.update',
    'role.delete',
    'role.permission.assign',
    'role.permission.remove',
    'role.permission.update',
    'helicopter.create',
    'helicopter.report.generate',
    'helicopter.update',
    'helicopter.delete',
    'facility.create',
    'facility.update',
    'facility.delete',
    'base.create',
    'base.update',
    'base.delete',
    'hems_base.create',
    'hems_base.update',
    'hems_base.delete',
    'bmd.create',
    'bmd.update',
    'bmd.delete',
    'medicine.create',
    'medicine.update',
    'medicine.delete',
    'vocation.create',
    'vocation.update',
    'vocation.delete',
    'opc.create',
    'opc.update',
    'opc.delete',
    'forces_present.create',
    'forces_present.update',
    'forces_present.delete',
    'hospital.create',
    'hospital.update',
    'hospital.delete',
    'health_insurance_companies.create',
    'health_insurance_companies.update',
    'health_insurance_companies.delete',
    'federal_state.create',
    'federal_state.update',
    'federal_state.delete',
    'nationality.create',
    'nationality.update',
    'nationality.delete',
    'icao.create',
    'icao.update',
    'icao.delete',
    'land.create',
    'land.update',
    'land.delete',
    'master_settings.create',
    'master_settings.update',
    'master_settings.delete',
    'file_manager.create',
    'file_manager.update',
    'file_manager.delete',
    'hems_duty_roster.create',
    'hems_duty_roster.update',
    'hems_duty_roster.delete',
    'air_rescuer_checklist.create',
    'air_rescuer_checklist.update',
    'air_rescuer_checklist.delete',
    'audit.read'
  );

-- +goose Down
ALTER TABLE permissions
  DROP COLUMN requires_pin;
