import { AUDIT_PAUSE_KEY } from '@tamanu/constants';
export async function up(query) {
    await query.sequelize.query(`
    CREATE OR REPLACE FUNCTION logs.is_audit_changes_enabled()
      RETURNS boolean
      LANGUAGE plpgsql
      STABLE PARALLEL SAFE
      AS $$
    BEGIN
      IF get_session_config ('${AUDIT_PAUSE_KEY}', 'false')::boolean THEN
        RETURN FALSE;
      END IF;
      RETURN TRUE;
    END;
    $$;
  `);
    await query.sequelize.query("DELETE FROM settings WHERE key = 'audit.changes.enabled';");
}
export async function down(query) {
    await query.sequelize.query(`
    CREATE OR REPLACE FUNCTION logs.is_audit_changes_enabled()
      RETURNS boolean
      LANGUAGE plpgsql
      STABLE PARALLEL SAFE
      AS $$
    BEGIN
      IF get_session_config ('${AUDIT_PAUSE_KEY}', 'false')::boolean THEN
        RETURN FALSE;
      END IF;
      RETURN coalesce((
        SELECT
          value::boolean
        FROM settings
        WHERE
          key = 'audit.changes.enabled'
          AND scope = 'global'), FALSE);
    END;
    $$;
  `);
}

//# sourceMappingURL=1778000000000-retireAuditChangesEnabledSetting.js.map